This is the mail archive of the
gcc@gcc.gnu.org
mailing list for the GCC project.
Re: Postioning of items within a class
On Wed, Jul 12, 2000 at 01:55:21PM -0400, Andrew Henderson wrote:
> ... so I'm somewhat stuck with converting inlined chunks of asm on the
> order of several hundred lines of asm per chunk.
Ug.
> A quick check into the offsetof() macro shows that it is designed for
> structures only. I'll have to experiment with it to see if I can coax it
> into working for classes as well. Joe's e-mail response lends a positive
> light to the possiblity of offsetof() working for what I need.
A (variant of a) hack that I've used before goes something like this.
You've got a file, mkasmoff.c that gets "compiled" before everything
else:
#include <stddef.h>
#define DEF(classname, membername) \
asm volatile("xyzzy off_" #classname "_" #membername " = %0" \
: : "i"(offsetof (classname, membername)))
#define NO_ASMOFF_INC
#include "world.h"
void dummy()
{
DEF(foo, m1);
DEF(foo, m2);
...
}
Now, you do
gcc -S mkasmoff.c -o - | grep xyzzy | sed 's/.*xyzzy //' > asmoff.inc
and you have a file that contains assembler definitions for each
of the struct/member pairs you care about. Now you put
#ifndef NO_ASMOFF_INC
asm (".include \"asmoff.inc\"");
#endif
somewhere in "world.h" and all of the inline assmbly will be able
to use these offsets.
Gross, I know, but effective.
r~
PS: The xyzzy and grep+sed trick is especially useful when cross-compiling
kernels, since you aren't able to actually run anything with the target
compiler to do a printf sort of solution.