KnowledgeHub
Questions
Tags
Users
Search
Alex Rivera
|
Logout
Edit Question
Title
Body
Probably a naïve question - I used to program 20 years ago and haven't coded much since. My memory of how the C preprocessor works has atrophied significantly since then... I am writing a very simple C program and I am trying to declare a few static global arrays, but the size of the arrays would be dependent (on a non-trivial way) on a MODE variable. Something like the simplified example below. Two quick points: I know I could just size the arrays according to the largest size needed by any MODE , but I don't want to that because (unlike in the simplified example below) sometimes a handful of these dimensions are going to be extremely large while others are tiny. Also, I want to use statically defined global arrays - rather than dynamically allocate them at runtime. I want the compiler to have the sizes at compile time. //** Simplified example of what I'd like to do **// #define SIZE_LIST_1[5] = {2, 7, 23, 33, 12, 76} // I don't think this is valid syntax #define SIZE_LIST_2[5] = {11, 65, 222, 112, 444} #define MODE 4 #define S1 SIZE_LIST_1[MODE] #define S2 SIZE_LIST_2[MODE] int a[S1], b[S2];
Tags (comma-separated)
Save Edits
Cancel