APL\360

Guy Sotomayor ggs at shiresoft.com
Sat Jan 30 00:03:08 CST 2021


On 1/29/21 4:32 PM, Fred Cisin via cctalk wrote:
>>>> if ( !(myfile = fopen( filename, "r"))
>
> On Fri, 29 Jan 2021, Guy Sotomayor via cctalk wrote:
>> In a lot of industry standard coding practices (MISRA, CERT-C) that 
>> type of statement is prohibited and *will* result in an error being 
>> reported by the checker/scanner.
>> The if statement in your example has at least 2 errors from MISRA's 
>> perspective:
>> * assignment within a conditional statement
>> * the conditional not being a boolean type (that is you can't assume 0
>>   is false and non-0 is true...you actually need to compare...in this
>>   case against NULL)
>
> That particular structure has become an industry standard.
> MOST dialects of C return a NULL pointer on fopen error.
> Similarly the code in strcpy has an assignment and is using the 
> numeric valus of each character as if it were boolean, with the 
> terminating NULL ending the while condition.


And unfortunately some industries it is prohibited.  Those industries 
*require* conformance to MISRA, CERT-C, ISO-26262 and others.  There is 
*no* choice since the code has to be audited and compliance is *not* 
optional.


-- 
TTFN - Guy



More information about the cctalk mailing list