From mboxrd@z Thu Jan 1 00:00:00 1970 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on polar.synack.me X-Spam-Level: X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00 autolearn=ham autolearn_force=no version=3.4.4 X-Google-Thread: 103376,ec21c3c7cdc7ff3e X-Google-Attributes: gid103376,public X-Google-Language: ENGLISH,ASCII-7-bit Path: g2news1.google.com!news3.google.com!border1.nntp.dca.giganews.com!border2.nntp.dca.giganews.com!nntp.giganews.com!news-xxxfer.readnews.com!news-out.readnews.com!spool-big1.readnews.com!not-for-mail Newsgroups: comp.lang.ada Subject: Re: private types From: "Peter C. Chapin" References: <1142279908.327131.230200@j52g2000cwj.googlegroups.com> <1259548.CMTukHGvVZ@linux1.krischik.com> <1172812.9zPbPKbdVq@linux1.krischik.com> Organization: Kelsey Mountain Software Message-ID: User-Agent: Xnews/5.04.25 Date: 20 Mar 2006 10:58:12 GMT NNTP-Posting-Host: e8842c6a.news.sover.net X-Trace: DXC=Q0T`6hKP75:hjHo25L]4D1K6_LM2JZB_3=;Mo8F;50S4:WUUlR<856?Sj@b=JHjB@?RmF2XhJ9]V> X-Complaints-To: abuse@sover.net Xref: g2news1.google.com comp.lang.ada:3480 Date: 2006-03-20T10:58:12+00:00 List-Id: Maciej Sobczak wrote in news:dvlu9d$mg6$1@sunnews.cern.ch: > Where did you read this? > NULL is not depreciated. It's defined in the header to be a > null-pointer constant, which is any integral const expression that > evaluates to 0. Possible definition is: > > #define NULL 0 > > Note: the following is explicitly prohibited: > > #define NULL (void*)0 This defintion of NULL is not workable in C++. This is because C++ does not allow pointers to void to be put into other pointer types without a cast. If the above definition was used the following would be an error: int *p = NULL; Thus in C++, NULL must be defined as the literal "0". Note that this issue does not come up in C because C's type system is more permissive. Thus the (void*)0 is often used in C. Because "NULL" just expands to "0" in C++, code using NULL can at times be misleading. For example consider void f(int); void f(char *); f(NULL); // Ambiguous, could call either f(int) or f(char *). This is a surprising error. Other surprises come up when passing NULL to functions taking a variable number of arguments. Type checking is essentially turned off for the variable arguments and thus if integers and pointers have different representations or if the NULL pointer must be handled in a special way (not all bits zero), errors can occur printf("The address is: %p\n", NULL); In C++ this passes the integer zero to printf, not a pointer. The compiler can't understand that "0" is a null pointer constant in this context because it doesn't know what type the second argument to printf is supposed to be. For these reasons many C++ experts recommend using "0" explicitly to represent NULL pointers and not the symbol NULL. This makes the problems above more apparent in the source and thus more likely that the programmer will notice them. Peter