#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.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
stuff.
George
-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/