I need to define many variables and I don’t want to do it one by one. Plus, I want to learn more about macros. So let’s say I have to define x1, x2, x3, x4, x5 like this:
int x1;
int x2;
int x3;
int x4;
int x5;
Can I do it with a macro? like this:
#define defint(i) int x(i)//x(i) does not work. I need to somehow combine x and i. How??
and then make a for loop for how many variables I want to define?
UPDATE: I’ll use it to define many handlers for many traps in some code for an Operating system and hence I don’t want to use array (I want my bootloader to be as small as possible :P)
UPDATE2: seems I have to make myself more clear. Since it’s os code, so it also has assembly code. so half code is in C and half in asm. I define all variables via macro in assembly and use them in C declaring them extern :).
Use token pasting:
Also, see how I did not include the trailing semi-colon, since you want that when the macro is used, to make it look like a statement.