Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
| From | Szabolcs Nagy <nsz@port70.net> |
|---|---|
| Newsgroups | comp.std.c |
| Subject | null pointer constant, address constant |
| Date | 2012-12-18 13:25 +0000 |
| Organization | Aioe.org NNTP Server |
| Message-ID | <kapqt2$es4$1@speranza.aioe.org> (permalink) |
it seems the definition of 'null pointer constant' relies on integer constant expressions (6.3.2.3p3) http://port70.net/~nsz/c/c11/n1570.html#6.3.2.3p3 so eg. (void*)((char*)1 - 1) is not a null pointer constant because pointer arithmetics cannot give an integer constant expression but at least this could be used in pointer initializers since address constants are allowed there (6.6p7) http://port70.net/~nsz/c/c11/n1570.html#6.6p7 but it seems 0 ? (void*)0 : (void*)0 is not a null pointer constant, nor an address constant it is mildly unexpected that this cannot be used as a null pointer constant (this matters when determining the type of ?: (6.5.15) expressions, assigning it to function pointers (6.5.16.1) or comparing it to function pointers (6.5.9)) but (for me at least) it's more surprising that this is not even a constant expression that can be used in initializers, ie. void *p = 0?(void*)0:(void*)0; is undefined behaviour if i read section 6.6 correctly (not even a constraint violation that requires a diagnostic) another similar surprising case is void *q = (void*)((char*)1 - (char*)1); the initializer is not an address constant, not a null pointer constant nor an address constant +- an integer constant expression. i wonder if my interpretation is right and if there is some rational behind this (my personal intuition is that integer constant expressions should be defined more generously and may be the result of pointer arithmetics if the pointers are casted integer constants or the difference of address constants, then these surprises would go away)
Back to comp.std.c | Previous | Next — Next in thread | Find similar | Unroll thread
null pointer constant, address constant Szabolcs Nagy <nsz@port70.net> - 2012-12-18 13:25 +0000
Re: null pointer constant, address constant James Kuyper <jameskuyper@verizon.net> - 2012-12-18 09:53 -0500
Re: null pointer constant, address constant Szabolcs Nagy <nsz@port70.net> - 2012-12-18 20:06 +0000
Re: null pointer constant, address constant James Kuyper <jameskuyper@verizon.net> - 2012-12-18 15:39 -0500
Re: null pointer constant, address constant Szabolcs Nagy <nsz@port70.net> - 2012-12-19 00:44 +0000
Re: null pointer constant, address constant James Kuyper <jameskuyper@verizon.net> - 2012-12-18 20:24 -0500
Re: null pointer constant, address constant Szabolcs Nagy <nsz@port70.net> - 2012-12-19 10:27 +0000
Re: null pointer constant, address constant James Kuyper <jameskuyper@verizon.net> - 2012-12-19 07:15 -0500
Re: null pointer constant, address constant Phil Carmody <thefatphil_demunged@yahoo.co.uk> - 2012-12-21 03:03 +0200
Re: null pointer constant, address constant James Kuyper <jameskuyper@verizon.net> - 2012-12-21 12:13 -0500
Re: null pointer constant, address constant Szabolcs Nagy <nsz@port70.net> - 2013-01-09 00:44 +0000
Re: null pointer constant, address constant James Kuyper <jameskuyper@verizon.net> - 2013-01-08 20:21 -0500
Re: null pointer constant, address constant Eric Sosman <esosman@comcast-dot-net.invalid> - 2013-01-08 20:46 -0500
Re: null pointer constant, address constant Shao Miller <sha0.miller@gmail.com> - 2012-12-18 20:37 -0500
Re: null pointer constant, address constant Shao Miller <sha0.miller@gmail.com> - 2012-12-18 16:15 -0500
Re: null pointer constant, address constant Keith Thompson <kst-u@mib.org> - 2012-12-18 15:52 -0800
Re: null pointer constant, address constant Shao Miller <sha0.miller@gmail.com> - 2012-12-18 19:12 -0500
Re: null pointer constant, address constant Shao Miller <sha0.miller@gmail.com> - 2012-12-18 19:51 -0500
Re: null pointer constant, address constant Keith Thompson <kst-u@mib.org> - 2012-12-18 17:02 -0800
Re: null pointer constant, address constant "christian.bau" <christian.bau@cbau.wanadoo.co.uk> - 2012-12-20 05:34 -0800
Re: null pointer constant, address constant James Kuyper <jameskuyper@verizon.net> - 2012-12-20 10:33 -0500
Re: null pointer constant, address constant James Kuyper <jameskuyper@verizon.net> - 2012-12-20 12:28 -0500
Re: null pointer constant, address constant Tim Rentsch <txr@alumni.caltech.edu> - 2012-12-20 21:13 -0800
Re: null pointer constant, address constant Tim Rentsch <txr@alumni.caltech.edu> - 2012-12-20 21:05 -0800
Re: null pointer constant, address constant Shao Miller <sha0.miller@gmail.com> - 2012-12-20 12:17 -0500
Re: null pointer constant, address constant Keith Thompson <kst-u@mib.org> - 2012-12-20 12:10 -0800
Re: null pointer constant, address constant Tim Rentsch <txr@alumni.caltech.edu> - 2012-12-20 21:25 -0800
Re: null pointer constant, address constant Shao Miller <sha0.miller@gmail.com> - 2012-12-18 14:02 -0500
Re: null pointer constant, address constant Szabolcs Nagy <nsz@port70.net> - 2012-12-18 20:09 +0000
Re: null pointer constant, address constant James Kuyper <jameskuyper@verizon.net> - 2012-12-18 15:54 -0500
Re: null pointer constant, address constant Shao Miller <sha0.miller@gmail.com> - 2012-12-18 16:18 -0500
csiph-web