Conditional stream opening and 22.3?

Moderators: misra-c, david ward

Post Reply
gs
Posts: 87
Joined: Thu Nov 18, 2004 1:39 am

Conditional stream opening and 22.3?

Post by gs » Fri Jul 12, 2013 5:05 pm

Does the rule prohibit cases like the following:

Code: Select all

if( someCondition )
    f = fopen( "apple", "r+" );
else
    f = fopen( "apple", "r" );
g = fopen( "apple", "r+" );

misra-c
Posts: 566
Joined: Thu Jan 05, 2006 1:11 pm

Re: Conditional stream opening and 22.3?

Post by misra-c » Tue Jul 16, 2013 8:42 am

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.
---
Posted by and on behalf of
the MISRA C Working Group

Post Reply

Return to “8.22 Resources”