MISRA Discussion Forums
Does Rule 11.9 allow indirect expansion from NULL? - 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.11 Pointer type conversions (https://forum.misra.org.uk/forumdisplay.php?fid=166)
+---- Thread: Does Rule 11.9 allow indirect expansion from NULL? (/showthread.php?tid=1272)



Does Rule 11.9 allow indirect expansion from NULL? - rgamble - 14-09-2016

Does the following example violate Rule 11.9?
Code:
#define FOO NULL
int32_t *p1 = FOO;



Re: Does Rule 11.9 allow indirect expansion from NULL? - dg1980 - 15-09-2016

rgamble Wrote:Does the following example violate Rule 11.9?
Code:
#define FOO NULL
int32_t *p1 = FOO;
There is a note in rule 11.9 that says:
Quote:a null pointer constant of the form (void*)0 is permitted, whether or not it was expanded from NULL
There is also the following sample code:
Code:
#define MY_NULL_2 (void*)0
if (p2 == MY_NULL_2)/*compliant*/
Given the fact that this is identical with your example after preprocessing stage, logic dictates it cannot be a violation.


Re: Does Rule 11.9 allow indirect expansion from NULL? - delta_controls - 15-09-2016

I don't think it is a violation. However, the intention of the rule is to increase clarity and your macro reduces clarity.

The note is not relevant to your example.

The compliant example given by @dg1980 is not necessarily identical, as the actual expansion of the NULL macro is implementation-defined.


Re: Does Rule 11.9 allow indirect expansion from NULL? - misra-c - 23-09-2016

Your example does not violate rule 11.9 as the value is derived from NULL.

Rule 11.9 permits "NULL", (void *)0 and any macros that expand to these values.