Alan Stern wrote:
> On Thu, 8 Feb 2007, Phil Endecott wrote:
>> > From a
>> > higher-level (source code) point of view, the alignment doesn't affect the 
>> > set of operations which can be applied to the data type.
>> 
>> It affects whether you can legally use & to take its address.
>
> Are you sure about that?  I would think that if you take the address of an
> unaligned quantity, you simply end up with an unaligned pointer, not with
> a compiler error.  (Remember, we're talking specifically about GCC here.  
> The official C language doesn't include any of these concepts.)

I'm not personally sure, but I'm repeating what I was told by the gcc 
people when I asked.  Search for my name in gcc-help in December 2006.  
I'm probably mis-remembering some of the details.  See e.g.

http://thread.gmane.org/gmane.comp.gcc.help/17551/focus=17554

In that message, I assert that it is unsafe "on some architectures" to 
take the address of an unaligned packed structure member, and am told 
that it is unsafe on *all* architectures because the compiler is 
allowed by the C standard to assume that the least significant bits of 
an int* are zero.

So it may be that even this code:

char* p1 = ....;
int*  p2 = (int*) p1;
char* p3 = (char*) p2;

Is, in theory, unsafe.

As I said before, just as you think you are starting to understand it, 
another level of complexity is revealed.  Personally I'm steering clear 
of the whole subject and not making any assumptions at all about how 
structs are laid out in memory.



Phil.





-------------------------------------------------------------------------
Using Tomcat but need to do more? Need to support web services, security?
Get stuff done quickly with pre-integrated technology to make your job easier.
Download IBM WebSphere Application Server v.1.0.1 based on Apache Geronimo
http://sel.as-us.falkag.net/sel?cmd=lnk&kid=120709&bid=263057&dat=121642
_______________________________________________
linux-usb-devel@lists.sourceforge.net
To unsubscribe, use the last form field at:
https://lists.sourceforge.net/lists/listinfo/linux-usb-devel

Reply via email to