Article View: comp.std.c
Article #4393Re: null pointer constant
From: Norman Diamond
Date: Mon, 27 Nov 1995 06:33
Date: Mon, 27 Nov 1995 06:33
37 lines
1978 bytes
1978 bytes
In article <49b202$62t@nntp.Stanford.EDU>, becker@Xenon.Stanford.EDU (Denizen of the Deep) writes: >If the type (void *) is not compatible with pointer-to-function types, >then why is the expression (void *)0 a legal null pointer constant? Consider a different but equally logical question: If the type (int) is not compatible with pointer-to-function types, then why is the expression 0 a legal null pointer constant? The answer to both questions is: Because the standard says they are. The standard defines this magic property for two kinds of expressions: (1) any integral constant expression with value 0, and (2) any integral constant expression with value 0 cast to type (void *). An example of the first kind is: (int)0 Examples of the second kind are: (void *)0 (void *)(int)0 A faulty example, which in fact is not a null pointer constant, is: (void *)(void *)0 An example which might or might not be, depending on the implementation definition of NULL, is: (void *)NULL >Since the null pointer constant is assignable to a pointer-to-function, >it seems that this is rather misleading. Since any null pointer constant is assignable to a pointer-to-function, do you consider it misleading that 0 is a null pointer constant? -- << If this were the company's opinion, I would not be allowed to post it. >> "I paid money for this car, I pay taxes for vehicle registration and a driver's license, so I can drive in any lane I want, and no innocent victim gets to call the cops just 'cause the lane's not goin' the same direction as me" - J Spammer
Technical Details
Message-ID:
<49bm3b$shm@usenet.pa.dec.com>Path:
arc1-ca.pugleaf.net!jrd.dec.com!diamondReferences:
<49b202$62t@nntp.Stanford.EDU>Show Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!jrd.dec.com!diamond From: diamond@jrd.dec.com (Norman Diamond) Newsgroups: comp.std.c Subject: Re: null pointer constant Date: 27 Nov 1995 06:33:15 GMT Organization: DEC Japan Research and Development Center Distribution: world Message-ID: <49bm3b$shm@usenet.pa.dec.com> References: <49b202$62t@nntp.Stanford.EDU> NNTP-Posting-Host: jit533.jrd.dec.com