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]

Aliasing: reliable code or not?


I have code that goes something like this:

char *foo(char *buf){
   *buf++ = 42;
   *((short*)buf) = 0xfeed;
   buf += 2;
   *((int*)buf) = 0x12345678;
   buf += 4;
   *((int*)buf) = 0x12345678;
   buf += 4;
   return buf;
}

The buffer is really of type char. The above comes
from a pile of macros and inline functions (C99 code),
or alternately from a pile of evil C++ templates.

Real C99-compliance would be cute, but then again
the buffer will end up getting executed as x86 code.
Intentionally executing data is surely a standards
violation of the highest order.

I can't afford to just use "char" to do the writes.
Currently gcc won't merge those into larger writes.
Performance matters.

So, how likely is gcc to do what I obviously want?
It seems to be working right now...

It would be nice to have this documented to work,
just as was done with unions for type punning.
The next best would be a big giant warning and a
work-around that doesn't kill performance.


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