This is the mail archive of the
gcc@gcc.gnu.org
mailing list for the GCC project.
Re: [PATCH] C undefined behavior fix
- From: Florian Weimer <fw at deneb dot enyo dot de>
- To: jkl at miacid dot net
- Cc: "Joseph S. Myers" <jsm28 at cam dot ac dot uk>, 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, 05 Jan 2002 21:01:11 +0100
- Subject: Re: [PATCH] C undefined behavior fix
- References: <Pine.BSI.4.10.10201051111100.8542-100000@hevanet.com>
jkl@miacid.net writes:
> An arbitrary integer may be converted to a pointer.
> ^^^^^^^^^
This rule exists so that implementations are not forced to issue a
diagnostic for (char *)1.
> 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.
According to the standard, you say that you want to cast p to type
int. You cannot manipulate machine addresses in C because C is
defined as a high-level language, without backdoors to such low-level
concepts as machine addresses.
The fact that quite a few implementations traditionally provide
such backdoors in some cases does not mean that the C language is a
low-level language, or that all implementations (even future ones)
have to provide these backdoors.
> If the satandard has changed so this is no longer possible, there
> NEEDS to be some other way in the new standard to express the same
> concept, or large application domains where C is currently in use will
> stop working.
I don't think there are fundamental and conceptual changes in C99 in
this area. Even with previous C reversions, you should have read the
compiler manual carefully before doing address arithmetic.