Postioning of items within a class

Richard Henderson rth@cygnus.com
Wed Jul 12 16:41:00 GMT 2000


On Wed, Jul 12, 2000 at 12:05:39PM -0400, Andrew Henderson wrote:
> 1.  Is there a method by which GCC/GAS can do a similar type of
> substitution for offsets of items within classes (like MASM does in the
> example above)?

	asm ("movl %%eax, %0" : : "m"(my_pointer->item2));

is the best way.  That is, let gcc construct the entire memory reference.
Of course, you're limited to 10 asm arguments, so you can't do this for
an enormous block of code.  Of course, you probably don't want to be doing
enormous blocks of asms anyway.  (And in my experience VC++ programmers
drop to inline assembly way too often for things they don't need.  Just
converting the whole thing back to C would be a win.)

> 2.  Failing that, is there a GCC way of querying the class and getting
> the offsets of members within the class (perhaps an __attribute__ of
> some sort)?

There's offsetof, but that may only work for POD structures in C++.
I don't know for sure.


r~


More information about the Gcc mailing list