To: Deborah Donovan From: David R Tribble on Wed, Feb 11, 1998 12:47 AM Subject: Comments on ISO/IEC CD 9899 (C9X) Message-Id: <2.2.32.19980211030046.00f4e1fc@central.beasys.com> Mime-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Date: Tue, 10 Feb 1998 21:00:46 -0600 To: ddonovan@itic.nw.dc.us From: David R Tribble Subject: Comments on ISO/IEC CD 9899 (C9X) Public Comment Number(s) PC-____ to PC-____ ISO/IEC CD 9899 (SC22N2620) Public Comment =========================================== Date: 1998-02-10 Author: David R. Tribble Author Affiliation: Self Postal Address: 6004 Cave River Dr. Plano, TX 75093-6951 USA E-mail Address: dtribble@technologist.com david.tribble@central.beasys.com dtribble@flash.net Telephone Number: +1 972 738 6125, 16:00-00:00 UTC +1 972 964 1729, 01:00-05:00 UTC Fax Number: +1 972 738 6111 Number of individual comments: 1 ------------------------------------------------------------------------ Comment 1. Category: Normative change to existing feature retaining the original intent Committee Draft subsection: 7.1.6. Title: NULL macro type Detailed description: Section 7.1.6 [#3] states that the standard macro 'NULL' expands to an "implementation-defined null pointer constant". I feel that the standard ought to restrict the use of the 'NULL' macro to pointer expressions only, i.e., make it illegal to use 'NULL' as an integer expression. As defined currently, 'NULL' can be defined as '0' or '0L' as well as '((void*)0)'. The former two are integer constants, allowing for the possibility of 'NULL' being used as an integer constant on some implementations. Disallowing 'NULL' as an integer constant would make this dubious practice illegal. Proposal: I propose the following change to [7.1.6 #3]: [#3] The macros are NULL which expands to an implementation-defined null pointer constant of pointer type; and ... (The rest of the sentence is unchanged.) Discussion: [1] The use of 'NULL' as an integer constant is an inappropriate programming practice. Some examples are: int i = NULL; // Should be 0 char ch = NULL; // Should be '\0' or NUL memset(p, NULL, sz); // Should be '\0' or 0 if (ch > NULL) ... // Should be '\0' or 0 The 'NULL' macro ought to represent a pointer value, not simply a zero value. [2] Many implementations could define 'NULL' thus: #define NULL ((void*)0) which meets the requirements above. A few implementations use a representation other than "all bits zero" to represent a null pointer, so they could define 'NULL' as something like this: #define NULL ((void*)0x80000000) // ala IBM CICS The definition above does not restrict the type of 'NULL' to anything other than a pointer type; it is not required to be 'void*' per se, but could be whatever type the compiler vendor deems appropriate. For example: #define NULL __null // Vendor A #define NULL ((__notype*)0) // Vendor B In these cases, '__null' and '__notype' are implementation-specific reserved words with special meanings. (It is assumed that in both cases the type of 'NULL' is "implementation-specific pointer type".) ------------------------------------------------------------------------