I have an array (C language) that should be initialized at compile time.
For example:
DECLARE_CMD(f1, arg);
DECLARE_CMD(f2, arg);
The DECLARE_CMD is called from multiple files.
I want this to be preprocessed in.
my_func_type my_funcs [] = {
&f1,
&f2
}
It is possible, with a macro, to append items to an static array?
I am using C99 (with GNU extensions) on gcc4.
NOTE: in your question there are semicolons at the end of every line. This will seriously interfere with any attempt to use these macros. So it depends on where and how the
DECLARE_CMD(...)lines are found, and whether you can fix the semicolon problem. If they are simply in a dedicated header file all by themselves, you can do:…which gets turned into:
Read The New C: X Macros for a good explanation of this.
If you can’t get rid of the semicolons, this will be processed to:
… which is obviously a syntax error, and so this won’t work.