This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

Compiler/TM4C1290NCPDT: C99 Compliant #define NULL ((void *) 0)

Part Number: TM4C1290NCPDT

Tool/software: TI C/C++ Compiler

Compiler Team,

Our customer has also raised the point that to be C99 compliant, the proper NULL define should be:  #define NULL ((void *) 0)

However, this is not the case currently.  We realize that while we are not 100% C99 compliant, we DO however support many C99 extensions.

That being said, in order to be consistent, we should also be compliant with this convention.

See below graphics for more 'evidence'.  Comments indeed welcomed!

TY,
CY

  • The photographed C99 page says: "The macros are NULL which expands to an implementation-defined null pointer constant, ..."

    The same C99 standard defines a null pointer constant as follows:

    "An integer constant expression with the value 0, or such an expression cast to type void *, is called a null pointer constant."

    So defining NULL as 0 seems perfectly C99 compliant to me.

  • Hi Markus,

    Appreciate your input! However, while I understand and in general agree with you, our customer basically feels otherwise. I'm hopeful to find something affirmative that eases their concern or at least allows us to present a response like what you've shared.

    TY,
    CY
  • The C99 standard is the governing document in this case.  And it is pretty clear.  It says NULL:

    expands to an implementation-defined null pointer constant

    So it is valid for NULL to be defined to a simple 0.

    Thanks and regards,

    -George

  • Chris Yorkey said:
    while I understand and in general agree with you, our customer basically feels otherwise.

    The photograph you post of the MISRA C standard includes the following text listing "conforming definition[s] of NULL", including 0, so the MISRA standard explicitly blesses implementations which define NULL as plain 0:

    0

    (void*)0

    ( ( ( 0 ) ) )

    ( ( ( 1 - 1 ) ) )

  • Team,

    Our customer has reported the following:

    -----

    We studied further into the issue of NULL, and found we had a misunderstanding.  In the MISRA-2012 standard (Rule 11-9, page 102), we had overlooked this:

    The following example is compliant because the use of the macro NULL provided by the implementation is always permitted, even if it expands to an integer constant expression with the value 0.

    #include <stddef.h>

    extern void f( uint8_t *p );

     

    /* Compliant for any conforming definition of NULL, such as:

        0

        (void *)0

        ( ( ( 0 ) ) )

        ( ( ( 1 - 1 ) ) ) */

    f( NULL );

     

    Therefore, we are in agreement that the present implementation in CCS of NULL in stddef.h is allowed (ie #define NULL 0), and is acceptable under MISRA-2012 as presently written.

    We apologize for creating confusion.  Please relay to your colleagues.

    -----

    Closed.

    Thank you very much,

    CY