lkml.org 
[lkml]   [1999]   [Aug]   [3]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
    /
    Date
    From
    SubjectRe: WARNING: GCC 2.9.5 & Linux
    vonbrand@sleipnir.valparaiso.cl (Horst von Brand)  wrote on 02.08.99 in <199908030032.UAA01464@sleipnir.valparaiso.cl>:

    > Steve Dodd <dirk@loth.demon.co.uk> said:
    >
    > [...]
    >
    > > What /is/ the issue with the strict aliasing code? I was under the
    > > impression that it "merely" screwed up code that did icky things with
    > > pointers to members of unions. Comments made here about Linus' view on
    > > the thing sounds like it is some horrendous problem that may never get
    > > sorted. Which is the case?
    >
    > The ANSI C standard prohibits accessing data through a pointer to a
    > different type. I.e., this is wrong:
    >
    > int *pi = ...;
    > char *pc;
    >
    > pc = (char *) pi;
    >
    > *pi = 117; /* 1st */
    > *pc = 'a'; /* 2nd */
    > ... *pi ... /* 3rd: Illegal */
    >
    > Note that 3rd is illegal because we stored there through pc, an char * and
    > we are going to access it again at 3rd through a int *. It is fine (AFAIU)
    > if you store a char though pc and access it as a char later. The point is
    > that this is _hard_ (probably impossible in the general case) to detect for
    > a compiler, so the compiler is allowed to assume that *pi does not change,
    > since no accesses through an int * could have changed *pi. So it could
    > reorder stuff so that the setting at 2nd is done _after_ the line marked
    > 3rd above...

    Nearly. Except it's defined to be ok if one of your two pointers is a
    char* pointer, so your example doesn't work. Try int* and short*, for
    example.

    MfG Kai

    -
    To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
    the body of a message to majordomo@vger.rutgers.edu
    Please read the FAQ at http://www.tux.org/lkml/

    \
     
     \ /
      Last update: 2005-03-22 13:53    [W:0.022 / U:0.524 seconds]
    ©2003-2016 Jasper Spaans. hosted at Digital OceanAdvertise on this site