This is the mail archive of the gcc-bugs@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: Possible egcs-980115 bug handling pointer casts


Jason Merrill writes:
> It's valid, but it invokes undefined behavior.  You'd be better off using a
> union.

In what sense is it undefined?  If I take a pointer to a 32 bit int and convert
it to a pointer to a 16 bit short isn't it defined that only 16 bits of memory
will be altered by storing a value through that pointer?  What I'm seeing is
32 bits of memory is altered.  I realize that the layout of a number in memory
isn't defined, that isn't my issue.  I though (at least from a practical
standpoint) that accessing a 16 bit memory block through a pointer was
somewhat defined.  K&R states:

  A6.6  A pointer to one type may be explicitly converted to another type.
        The resulting pointer may cause addressing exceptions if the subject
        pointer does not refer to an object suitably aligned in storage.
        It is guaranteed that a pointer to an object may be converted to
        a pointer to an object whose type requires less or equally strict
        storage alignment and back again without change;

I realize that if I was designing a program that I could use a union.  My
concern isn't a program I'm writing, rather it is that egcs appears (at
least from a practical standpoint) to be generating incorrect code.

BTW, Alasdair Baird posted a message recently to egcs describing a problem
compiling X11 code which sounds similar to what I'm seeing.  It's possible
that his solution (which involved a change to recog.c) may also address the
above issue.

-- John
-------------------------------------------------------------------------
|   Feith Systems  |   Voice: 1-215-646-8000  |  Email: john@feith.com  |
|    John Wehle    |     Fax: 1-215-540-5495  |                         |
-------------------------------------------------------------------------



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