MISRA Discussion Forums
Conditional stream opening and 22.3? - Printable Version

+- MISRA Discussion Forums (https://forum.misra.org.uk)
+-- Forum: MISRA C (https://forum.misra.org.uk/forumdisplay.php?fid=4)
+--- Forum: MISRA C:2012 and MISRA C:2023 guidelines (https://forum.misra.org.uk/forumdisplay.php?fid=21)
+---- Forum: 8.22 Resources (https://forum.misra.org.uk/forumdisplay.php?fid=177)
+---- Thread: Conditional stream opening and 22.3? (/showthread.php?tid=969)



Conditional stream opening and 22.3? - gs - 12-07-2013

Does the rule prohibit cases like the following:
Code:
if( someCondition )
    f = fopen( "apple", "r+" );
else
    f = fopen( "apple", "r" );
g = fopen( "apple", "r+" );



Re: Conditional stream opening and 22.3? - misra-c - 16-07-2013

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.