This is the mail archive of the gcc@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]
Other format: [Raw text]

Re: [PATCH] C undefined behavior fix


Linus Torvalds <torvalds@transmeta.com> writes:

> I'm saying that the standard clearly says that _any_integer_ can be
> converted into a pointer

Yes, but you have to read the whole paragraph:

       [#6]  Any  pointer type may be converted to an integer type.
       Except   as   previously   specified,    the    result    is
       implementation-defined.  If the result cannot be represented
       in the integer type, the behavior is undefined.  The  result
       need not be in the range of values of any integer type.

A less verbose version is: "Any pointer type may be converted to an
integer type, and the behavior is undefined."  In fact, this section
is an example that implementation-defined behavior can include
undefined behavior.

The first requirement is necessary so that you can write "(foo *) i"
at all, otherwise the compiler would have to reject such casts in
order to be conforming.

So could we please stop this pointless discussion.  Obviously, you
dislike the behavior of GCC.  But GCC behavior can be changed right
now, if there's consensus, and if it is implementable in the GCC 3.1
frame.  However, if we want to make a change, we need a sufficiently
detailed proposal for new behavior.


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