[Issue 1875] &null[x] compiles and runs, giving x

d-bugmail at puremagic.com d-bugmail at puremagic.com
Wed Feb 27 22:54:17 PST 2008


http://d.puremagic.com/issues/show_bug.cgi?id=1875





------- Comment #2 from matti.niemenmaa+dbugzilla at iki.fi  2008-02-28 00:54 -------
I don't think it makes sense for void pointers to be indexable, just like they
aren't in C.

For that matter, I think indexing pointer constants in general deserves a
warning, at least. For the case of null, it should be an error: why is indexing
cast(int[])null an array bounds error, but indexing null as a pointer isn't? In
both cases, you know there are no valid elements there - that's the definition
of the null pointer.

You'll note that the results are unpredictable: &null[420] is 420, but
&(cast(int*)null)[420] is 1680 - that's int.sizeof * 420. And similarly, for a
long, you get 3360.


-- 



More information about the Digitalmars-d-bugs mailing list