Question for all...
I'm trying to determine the size of a global structure. It has to be declared globally because it's used in several different files. When compiling (BCC32) the code I get the error:
Error E2109 MainTest.c 9: Not an allowed type in function main
I know this is happening because the array of structures is of an undefined size []. But I can't define the size ahead of time.
The code was compiled from the command line with the command:
BCC32 Test.c MainTest.c
If there is a better way to do this I'm open to suggestions.
Here's a small version of the code:
MainTest.c:
Test.h:
Test.c:
I'm trying to determine the size of a global structure. It has to be declared globally because it's used in several different files. When compiling (BCC32) the code I get the error:
Error E2109 MainTest.c 9: Not an allowed type in function main
I know this is happening because the array of structures is of an undefined size []. But I can't define the size ahead of time.
The code was compiled from the command line with the command:
BCC32 Test.c MainTest.c
If there is a better way to do this I'm open to suggestions.
Here's a small version of the code:
MainTest.c:
Code:
#include "test.h" #include "stdlib.h" #include "stdio.h" void main(void) { int i; i = sizeof(TextStruct)/sizeof(*TextStruct); printf("Size = %d\n", i); }
Code:
typedef struct { char *text; int j; } TextStructDef; extern TextStructDef TextStruct[];
Code:
#include "test.h" TextStructDef TextStruct[]= { {"aaa", 1}, {"bbb", 2}, {"ccc", 3}, };
Comment