This is the mail archive of the
gcc@gcc.gnu.org
mailing list for the GCC project.
Re: [PATCH] C undefined behavior fix
- From: "Joseph S. Myers" <jsm28 at cam dot ac dot uk>
- To: <jkl at miacid dot net>
- Cc: Florian Weimer <fw at deneb dot enyo dot de>, <dewar at gnat dot com>, <Dautrevaux at microprocess dot com>, <paulus at samba dot org>, <Franz dot Sirl-kernel at lauterbach dot com>, <benh at kernel dot crashing dot org>, <gcc at gcc dot gnu dot org>, <jtv at xs4all dot nl>, <linux-kernel at vger dot kernel dot org>, <linuxppc-dev at lists dot linuxppc dot org>, <minyard at acm dot org>, <rth at redhat dot com>, <trini at kernel dot crashing dot org>, <velco at fadata dot bg>
- Date: Sat, 5 Jan 2002 19:37:48 +0000 (GMT)
- Subject: Re: [PATCH] C undefined behavior fix
On Sat, 5 Jan 2002 jkl@miacid.net wrote:
> Wat this last bit added to the standard after ANSI/ISO 9899-1990? I'm
> looking through my copy and I can't find it. All I can find is that
I was quoting from the GCC manual (providing the documentation
implementations are required to provide of implementation-defined
behaviour); of course the subclause numbers are different in C99 (from
which the subclause numbers in the GCC manual are given) from those in
C90. Perhaps once all the documentation for implementation-defined
behaviour in C99 is present I'll go over what's required to document it
all relative to C90 as well.
> I interpret this to mean that one MAY use integer arithmatic to
> do move a pointer outside the bounds of an array. Specifically, as soon
> as I've cast the pointer to an integer, the compiler has an obligation to
> forget any assumptions it makes about that pointer. This is what casts
> from pointer to integer are for! when i say (int)p I'm saying that I
> understand the address structure of the machine and I want to manipulate
> the address directly.
Just because you've created a pointer P, and it compares bitwise equal to
a valid pointer Q you can use to access an object, does not mean that P
can be used to access that object. Look at DR#260, discussing the
provenance of pointer values, which arose from extensive discussion in the
UK C Panel, and if you think it should be resolved otherwise from how we
(UK C Panel) proposed then raise your position on it at a meeting of your
National Body before the next WG14 meeting.
http://std.dkuug.dk/JTC1/SC22/WG14/www/docs/dr_260.htm
--
Joseph S. Myers
jsm28@cam.ac.uk