Re: [RFC] Standard way of generating assembler offsets

From: george anzinger (
Date: Mon Oct 08 2001 - 14:00:38 EST

Georg Nikodym wrote:
> At the risk of sticking my foot in it, is there something wrong with the
> ANSI C offsetof() macro, defined in <stddef.h>?
> --Georg
No, and it could have been (and was) written prio to ANSI C defining
it. Something like:

#define offsetof(x, instruct) &((struct instruct *)0)->x

The issues that CPP resolves have to deal with the following sort of

struct instruct {
        struct foo * bar;
        int diddle_flag;
        int diddle_array[CONFIG_DIDDLE_SIZE];
        int x;

Or for the simple need for a constant:

#define Const (CONFIG_DIDDLE_SIZE * sizeof(int))

Of course you could have any number of constant operators in the
expression. Note also, that the array in the structure above is defined
by a CONFIG symbol. This could also involve math, i.e.:


and so on. All in all, it best to let CPP do what it does best and
scarf up the result:

#define GENERATE_CONSTANT(name,c) printf(#name " equ %d\n",c)



In the code we did, we put all the GENERATE macros in a .h file. The
the code looked like:

#include.... all the headers needed....

#include <generate.h>

GENERATE.... all the generate macro calls...

} // all done (assumes that the "main(){" is in the generate.h file)

This whole mess was included as comments in the asm file. The make rule
then used a sed script to extract it, compile and run it to produce a
new header file which the asm source included outside of the above

To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to
More majordomo info at
Please read the FAQ at

This archive was generated by hypermail 2b29 : Mon Oct 15 2001 - 21:00:19 EST