APL\360
Chuck Guzis
cclist at sydex.com
Fri Jan 29 20:28:00 CST 2021
On 1/29/21 4:13 PM, 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)
Or zero; but then many current C (not C++) implementations do not define
an intrinsic boolean type. When writing using gcc, for example, I have to
#include <stdbool.h>
So, that leaves us with the value of NULL:
3.2.2.3 Pointers
An integral constant expression with the value 0, or such an
expression cast to type void * , is called a null pointer constant. If a
null pointer constant is assigned to or compared for equality to a
pointer, the constant is converted to a pointer of that type. Such a
pointer, called a null pointer, is guaranteed to compare unequal to a
pointer to any object or function.
--Chuck
More information about the cctalk
mailing list