This is the mail archive of the gcc@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]

enums and null pointer constants


c-parse.in, in the mess for parsing primary: IDENTIFIER, has

  if (TREE_CODE ($$) == CONST_DECL)
    {
      $$ = DECL_INITIAL ($$);
      /* This is to prevent an enum whose value is 0
	 from being considered a null pointer constant.  */
      $$ = build1 (NOP_EXPR, TREE_TYPE ($$), $$);
      TREE_CONSTANT ($$) = 1;
    }

Note the comment.  Now note section 6.3.2.3 para 3 of C99:

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

also section 6.6 para 6:

	An /integer constant expression/ shall have integer type and
	shall only have operands that are integer constants,
	*enumeration constants*, character constants, sizeof expressions
	whose results are integer constants, and floating constants
	that are the immediate operands of casts.

// = italics in standard, ** = my emphasis.

Taken together, I believe this means that an enum with value 0 is to
be considered a null pointer constant, so the comment and the build1
operation are incorrect.

zw

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]