This is the mail archive of the
gcc@gcc.gnu.org
mailing list for the GCC project.
Re: [PATCH] C undefined behavior fix
- From: jtv <jtv at xs4all dot nl>
- To: mike stump <mrs at windriver dot com>
- Cc: Dautrevaux at microprocess dot com, dewar at gnat dot com, gcc at gcc dot gnu dot org, linux-kernel at vger dot kernel dot org, paulus at samba dot org, trini at kernel dot crashing dot org, velco at fadata dot bg
- Date: Tue, 8 Jan 2002 12:33:32 +0100
- Subject: Re: [PATCH] C undefined behavior fix
- References: <200201080016.QAA12225@kankakee.wrs.com>
On Mon, Jan 07, 2002 at 04:16:32PM -0800, mike stump wrote:
>
> I assume you meant something like this:
>
> char * volatile cp;
>
> main() {
> return cp - cp;
> }
No. No. In this case you're giving cp external linkage, which means it
can be observed from the outside. Plus, you're reading it multiple times,
which in the case of volatile definitely means it should be read multiple
times because it might be modified by something external between those
reads, and that may be exactly what you want to observe with your code.
What I mean (and what we're seeing in RELOC) is more like this:
char *foo() {
char * volatile cp = NULL;
return cp;
}
Jeroen