Gabriel Sechan wrote:
----------------------------------------
Date: Tue, 15 Jan 2008 21:23:17 -0800
From: [EMAIL PROTECTED]
To: [email protected]
Subject: Re: Where are the software engineers of tomorrow?
{ int x[10]; int* y;
y = x;
y += 12; /* C standard says this line can crash your program */
}
No, it doesn't. Pointer arithmetic is explicitly allowed by the standard.
That means that y is advanced by 12 integers.
No. Pointer arithmetic is allowed, but you're not allowed to advance
more than one past the end of the array you're pointing to or to before
the array you're pointing to. I.e., you could add 10 to y there, but not
12. For example, check out the 95th page (labeled page 83) of the
standard http://www.open-std.org/jtc1/sc22/wg14/www/docs/n1124.pdf
Constraints 8 and 9 basically say for addition, you can't run off the
array, and for subtraction, they both have to point to the same array.
If you think that's not the right interpretation, explain why the last
half of paragraph 3 in section 6.5.3 (90th page) is there, which says
"*&(x) works for any expression for x" basically.
It's also possible my compiler defines "casting an integer to a pointer"
to always return a representation for the pointer (a trap
representation, basically) that aborts the program as soon as
referenced. C interpreters tend to work that way.
--
Darren New / San Diego, CA, USA (PST)
It's not feature creep if you put it
at the end and adjust the release date.
--
[email protected]
http://www.kernel-panic.org/cgi-bin/mailman/listinfo/kplug-lpsg