george anzinger wrote: > > Georg Nikodym wrote: > > > > At the risk of sticking my foot in it, is there something wrong with the > > ANSI C offsetof() macro, defined in ? > > > > --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 > structure: > > struct instruct { > struct foo * bar; > #ifdef CONFIG_OPTION_DIDDLE > int diddle_flag; > int diddle_array[CONFIG_DIDDLE_SIZE]; > #endif > 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.: > > #define CONFIG_DIDDLE_SIZE CLOCK_RATE / HZ > > 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) > > then: > > GENERATE_CONSTANT(diddle_size,CONFIG_DIDDLE_SIZE); > > 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.... 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 > stuff. > > George My script already handles that, everything is first passed through CPP and the member offset are varied correctly according to any compilation options. I included the script and the results of two runs. 1. ./h2inc tst.h >tst.inc 2. ./h2inc --cflags="-DSHOW_HIDDEN -I./" >tst-hidden.inc Regards