This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
Re: PR3609
- To: Mark Mitchell <mark at codesourcery dot com>
- Subject: Re: PR3609
- From: Geoff Keating <geoffk at geoffk dot org>
- Date: 09 Aug 2001 18:41:18 -0700
- CC: "gcc-patches at gcc dot gnu dot org" <gcc-patches at gcc dot gnu dot org>, Alan Lehotsky <apl at alum dot mit dot edu>, Jan Hubicka <jh at suse dot cz>
- References: <302210000.997395509@gandalf.codesourcery.com>
The appropriate place in the standard is section 6.3.2.3 paragraph 5,
which says
An integer may be converted to any pointer type. Except as previously
specified, the result is implementation-defined, might not be correctly
aligned, might not point to an entity of the referenced type, and
might be a trap representation.
Thus, in the expression
(char *)(((size_t)"foo") + 10)
the implementation has complete freedom to do pretty much whatever it
likes. Merely executing this as a statement could create a trap
representation, which could cause compile-time or run-time errors or
any other behaviour the implementation can create. It is permitted
for a compiler to give a fatal error on seeing this construct, or even
the similar construct
(char *)(size_t)"foo"
in fact, paragraph 6 says that even
(size_t)"foo"
can cause undefined behaviour.
--
- Geoffrey Keating <geoffk@geoffk.org>