I did want a global const, so I took laserlight's advice of implementing the #define. Now I have:
file2.h
Code:
struct line { char *string_var; int some_const; };
extern CONST_1;
extern CONST_2;
extern CONST_3;
file2.c
Code:
#define CONST_1 1;
#define CONST_2 2;
#define CONST_3 3;
struct line table_of_lines[] = {
"string1", CONST_1,
"another_string1", CONST_1,
"string3", CONST_3,
NULL, 0
};
And this is able to compile without error. Thanks!
I am now trying to use these values in a switch statement like so:
file1.c
Code:
#include <stdio.h>
#include "file2.h"
int main() {
int index;
for (index=0; table_of_lines[index].string_var; index++) {
switch(table_of_lines[index].some_const) {
case CONST_1:
printf("String of kind 1: %s\n", table_of_lines[index].string_var);
break;
case CONST_1:
printf("String of kind 2: %s\n", table_of_lines[index].string_var);
break;
case CONST_1:
printf("String of kind 3: %s\n", table_of_lines[index].string_var);
break;
}
}
}
and i am getting errors for these variables that say:
file1.c... error: case label does not reduce to an integer constant
file1.c... error: case label does not reduce to an integer constant
file1.c... error: case label does not reduce to an integer constant
or if I just try to use one of these variables in file1.c
Code:
#include <stdio.h>
#include "file2.h"
int main() {
printf("%d\n", CONST_1);
return 0;
}
, I get:
undefined reference to 'CONST_1'