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!news4.google.com!news2.volia.net!newsfeed01.sul.t-online.de!newsfeed00.sul.t-online.de!t-online.de!130.59.10.21.MISMATCH!kanaga.switch.ch!news-zh.switch.ch!switch.ch!cernne03.cern.ch!cern.ch!news From: Maciej Sobczak Newsgroups: comp.lang.ada Subject: Re: private types Date: Mon, 20 Mar 2006 14:06:49 +0100 Organization: CERN - European Laboratory for Particle Physics Message-ID: References: <1142279908.327131.230200@j52g2000cwj.googlegroups.com> <1259548.CMTukHGvVZ@linux1.krischik.com> <1172812.9zPbPKbdVq@linux1.krischik.com> NNTP-Posting-Host: abpc10883.cern.ch Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii; format=flowed Content-Transfer-Encoding: 7bit X-Trace: sunnews.cern.ch 1142860009 17370 (None) 137.138.37.241 X-Complaints-To: news@sunnews.cern.ch User-Agent: Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.7.12) Gecko/20060203 Red Hat/1.7.12-1.1.3.4 X-Accept-Language: en-us, en In-Reply-To: Xref: g2news1.google.com comp.lang.ada:3483 Date: 2006-03-20T14:06:49+01:00 List-Id: Peter C. Chapin wrote: >>Note: the following is explicitly prohibited: >> >>#define NULL (void*)0 > > This defintion of NULL is not workable in C++. Which we've already cleared. :) > Thus in C++, NULL must be defined as the literal "0". Not exactly. It can be anything that is an integral constant expression evalutating to zero. Thus, "0" is one obvious choice, but not any better than, say, "0L", "'\0'" or even "(125 - 5 * 5 * 5)". > 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. That's why one of the sweeties in the upcoming C++ standard is a new keyword nullptr, which will be useable only in those contexts where a pointer type is expected, so that: f(nullptr); will always choose the second overload from the above. > Other surprises come up when passing NULL to > functions taking a variable number of arguments. Such functions are FUBARed anyway. :) > 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. On the other hand, for the human reader "NULL" is immediately associated with some special pointer value, not with not-at-all-special integer, so that the following: if (item != NULL) ... is also immediately recognized as a test against *existence* of some item (which also implies that item is a pointer), not as a test against item's integer value. In such contexts I use NULL. As you see, this subject has many faces. I invite you to comp.lang.c++.moderated to discuss them in more depth. -- Maciej Sobczak : http://www.msobczak.com/ Programming : http://www.msobczak.com/prog/