Re: usb: descriptor structures have to be packed

David Brownell <[email protected]>
Newsgroups gmane.linux.usb.devel
Message-ID <[email protected]>
On Wednesday 07 February 2007 2:14 pm, Phil Endecott wrote:
> David Brownell wrote:
> > On Wednesday 07 February 2007 10:41 am, Phil Endecott wr
> >> void inc(int* i) {
> >>    (*i)++;
> >> }
> 
> >> here's a quote from Paul Brook (http://gcc.gnu.org/ml/gcc-help/2006-12/msg00115.html):
> >> 
> >>    " the compiler is allowed to assume that the low 2 bits of an int* 
> >> are zero. "
> >
> > Unless it's declared as packed ... a fact which is 100% clear in the
> > definition of "packed".
> 
> Dave, how would you propose to re-write my "inc" function (above) to 
> declare i as a "packed int*"?  I have tried various things like

Did you try

	typedef int unaligned_int __attribute__((aligned(1)));

and suchlike?

I was a bit loose above.  The constraint is really about alignment,
and what's 100% clear is that there _is_ such a constraint on those
pointers, because they're from a struct declared as "packed".  The
normal GCC rules ("natural alignment" of pointer target) do not apply.

If GCC doesn't allow that, or doesn't recognize that a pointer to
an unaligned int can't be used where a "normal" pointer is needed,
then the issue would appear to be that the best GCC can do is warn
when you take the address of such an unaligned field.


> 
> void inc(int __attribute__((packed)) * i)
> void inc(int * __attribute__((packed)) i)
> void inc(int * i __attribute__((packed)))
> void inc(int __attribute__((aligned(1))) * i)
> void inc(int * __attribute__((aligned(1))) i)
> void inc(int * i __attribute__((aligned(1))))
> 
> and I get variously
> 
> warning: ‘packed’ attribute ignored
> error: alignment may not be specified for ‘i’
> 
> or no message at all, and I only ever get loadword-add-storeword code 
> generated.  My feeling is that there is no way to declare a "packed" or 
> "unaligned" pointer to an int, and so Paul is right.

He's clearly wrong about the semantics GCC has defined; that's
not debatable.  The documentation/specification is unambiguous.

What he may be right about is the semantics GCC _implemented_ which,
of course, are a horse of a different rainbow.  I have no idea what
kind of attributes pointers carry around inside GCC.

- Dave


-------------------------------------------------------------------------
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
_______________________________________________
[email protected]
To unsubscribe, use the last form field at:
https://lists.sourceforge.net/lists/listinfo/linux-usb-devel
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.