This is the mail archive of the gcc-patches@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]

Re: PR3609



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>


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]