0

I'm trying to create a struct with an array inside. The array size, I'm hoping, should be set at compile time. That is it's hard coded but uses a variable so I can change it easily in the code. Problem is I'm getting linker errors when I use const int in the header ahead of the struct definition. Here's my code:

from the header file:

const int t_Module_qInternalParams =64;

typedef struct Module{
    double internalParams[t_Module_qInternalParams];
} t_Module;
matt
  • 51
  • 3

1 Answers1

3

This:

const int t_Module_qInternalParams = 64;

Is a constant in the sense that the object cannot be modified after initialization, but it's still a variable. Especially, t_Module_qInternalParams is not a compile-time constant, as required in your declarator.

A simple solution is to use a preprocessor macro instead:

#define MODULE_INTERNALPARAMS 64

This just expands to 64 before the compiling phase starts, and of course, 64 is a compile-time constant.