0

I am trying to crate a parametric static array in a header file. Let me elaborate my requirement

Wanted to create below array in header file statically which can be resolved at compile time

static char test_array[][256] = {   
                              "hello_1",
                              "hello_2",
                              "hello_3" };

I need to generate this using macro which can do substitution with %d for 1,2 and 3 and the number of parameter also not fixed. What I mean here is tomorrow this array I can simply change through header file to

static char test_array[][256] = {
                          "hello_1",
                          "hello_45",
                          "hello_39",
                          "hello_101" };

I have the code to do it at run time in .c file but specifically I want to do it in a header file through macros .

5
  • 2
    How do you expect to call the macro? Can you give an example? Maybe you need something else, not a syntax trick, but a tool that does this. Commented Oct 4, 2018 at 19:07
  • basically my aim is to create the array at compile time and I will simple use to pass the array to some function which will fetch some parameters based on the array Commented Oct 4, 2018 at 19:09
  • It is not good to define data in header file. But you can make a .c file with that, which can be included in another .c file. I don't see why you need a macro. If tomorrow will be different from yesterday or the day after, is the solution to have a dynamic array whose values are initialised from a file at run time? Commented Oct 4, 2018 at 19:16
  • The reason I ma saying it to be in macro is based on the #define my parameters will be different example #define a array will have two parameters and for #define b array will have three parameters Commented Oct 4, 2018 at 19:45
  • For compile-time generation of arrays like interpolation tables of sensors I sometime use COG Commented Oct 4, 2018 at 19:48

0

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.