This is the mail archive of the
gcc@gcc.gnu.org
mailing list for the GCC project.
Re: Postioning of items within a class
- To: Andrew Henderson <prometheus at lokigames dot com>
- Subject: Re: Postioning of items within a class
- From: Richard Henderson <rth at cygnus dot com>
- Date: Wed, 12 Jul 2000 16:41:52 -0700
- Cc: gcc at gcc dot gnu dot org
- References: <396C9753.9CCFF35B@lokigames.com>
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~