MISRA Discussion Forums

Full Version: Conditional stream opening and 22.3?
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Does the rule prohibit cases like the following:
Code:
if( someCondition )
    f = fopen( "apple", "r+" );
else
    f = fopen( "apple", "r" );
g = fopen( "apple", "r+" );
Quite simply, yes

The example you cite is no different to the example in the Guideline for !someCondition

However, of course, if the stream is closed before the subsequent opening, then that would be OK.