Does Rule 11.9 allow indirect expansion from NULL?

Moderators: misra-c, david ward

Post Reply
rgamble
Posts: 14
Joined: Fri Jul 20, 2007 7:54 pm

Does Rule 11.9 allow indirect expansion from NULL?

Post by rgamble » Wed Sep 14, 2016 3:23 pm

Does the following example violate Rule 11.9?

Code: Select all

#define FOO NULL
int32_t *p1 = FOO;

dg1980
Posts: 109
Joined: Wed Apr 27, 2016 2:33 pm
Company: Elektrobit Automotive GmbH

Re: Does Rule 11.9 allow indirect expansion from NULL?

Post by dg1980 » Thu Sep 15, 2016 8:39 am

rgamble wrote:Does the following example violate Rule 11.9?

Code: Select all

#define FOO NULL
int32_t *p1 = FOO;
There is a note in rule 11.9 that says:
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: Select all

#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.

delta_controls
Posts: 15
Joined: Wed Feb 03, 2016 2:15 pm
Company: Delta Controls Ltd

Re: Does Rule 11.9 allow indirect expansion from NULL?

Post by delta_controls » Thu Sep 15, 2016 4:10 pm

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.
Last edited by delta_controls on Thu Sep 15, 2016 4:17 pm, edited 3 times in total.

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

Re: Does Rule 11.9 allow indirect expansion from NULL?

Post by misra-c » Fri Sep 23, 2016 8:49 am

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

Post Reply

Return to “8.11 Pointer type conversions”