MISRA Discussion Forums
Rule 11.1 and NULL defined as ((void*) 0) - 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: 2004 rules (https://forum.misra.org.uk/forumdisplay.php?fid=17)
+---- Forum: 6.11 Pointer Type Conversions (https://forum.misra.org.uk/forumdisplay.php?fid=38)
+---- Thread: Rule 11.1 and NULL defined as ((void*) 0) (/showthread.php?tid=626)



Rule 11.1 and NULL defined as ((void*) 0) - roberto - 14-02-2009

Please consider the following test program:

Code:
#define NULL ((void*) 0)

struct super_block;
struct inode;

typedef int (*find_inode_t)(struct inode *, unsigned long, void *);


extern struct inode * iget4_locked(struct super_block *, unsigned long,
                   find_inode_t, void *);

static inline struct inode *iget(struct super_block *sb, unsigned long ino)
{
    struct inode *inode = iget4_locked(sb, ino, NULL, NULL);
    return inode;
}


My reading of rule 11.1 is that NULL (so defined, which is quite common) cannot be passed that way to iget4_locked(). However, since I see zillions of violations of this kind, I am caught by the doubt.
Many thanks,

Roberto


Re: Rule 11.1 and NULL defined as ((void*) 0) - misra-c - 07-04-2009

A NULL pointer constant (however defined) can be converted to, assigned to, or compared for equality to a function pointer. Note that this exception to the rule is discussed in the normative text above Rule 11.1.

Rule 11.1 will be amended in future to clarify this point.

Tracking ID: 18