B
B. Wood
I have a small program (see below) that demonstrates an error I am
getting when I build the program on a linux platform.
I first initialize an unsigned char array (lines 16).
I then initialize my array of my typedeffed structure (dataStruct)
(lines 18-24). I use my initialized unsigned character array to
initialize the unsigned character pointer member of the structure
(line 21).
I then do a for loop, dumping the initialized data in the array of
structures.
This compiles fine under Windows 2000 using Microsoft 32-bit C/C++
Optimizing Compiler Version 12.00.8804, with no errors or warnings and
executes as expected.
On a linux platform, running Red Hat Linux 7.1 2.96-98 using gcc
version 2.96 20000731 I get the following error:
- initializer element is not computable at load time
I get the error on line 21 where I initialize my structures unsigned
char pointer member with the initialized unsigned character array.
I get the same error on line 23 where the closing brace of the
structure member initialize is.
Does anyone have any ideas on what this could be.
1 typedef struct dataStruct_
2 {
3 unsigned char * buffer;
4 unsigned int length;
5 }
6 dataStruct;
7
8 int
9 main
10 (
11 int argc,
12 char * argv[]
13 )
14 {
15
16 unsigned char buffer[] = { 1,2,3,4,5 };
17
18 dataStruct data[] =
19 {
20 {
21 buffer,
22 sizeof(buffer)
23 }
24 };
25
26 int i;
27
28 for (i = 0; i < 5; i++)
29 {
30 printf("%d\n", data[0].buffer);
31 }
32 printf("data size = %d\n", data[0].length);
33
34 return (EXIT_SUCCESS);
35
36 }
getting when I build the program on a linux platform.
I first initialize an unsigned char array (lines 16).
I then initialize my array of my typedeffed structure (dataStruct)
(lines 18-24). I use my initialized unsigned character array to
initialize the unsigned character pointer member of the structure
(line 21).
I then do a for loop, dumping the initialized data in the array of
structures.
This compiles fine under Windows 2000 using Microsoft 32-bit C/C++
Optimizing Compiler Version 12.00.8804, with no errors or warnings and
executes as expected.
On a linux platform, running Red Hat Linux 7.1 2.96-98 using gcc
version 2.96 20000731 I get the following error:
- initializer element is not computable at load time
I get the error on line 21 where I initialize my structures unsigned
char pointer member with the initialized unsigned character array.
I get the same error on line 23 where the closing brace of the
structure member initialize is.
Does anyone have any ideas on what this could be.
1 typedef struct dataStruct_
2 {
3 unsigned char * buffer;
4 unsigned int length;
5 }
6 dataStruct;
7
8 int
9 main
10 (
11 int argc,
12 char * argv[]
13 )
14 {
15
16 unsigned char buffer[] = { 1,2,3,4,5 };
17
18 dataStruct data[] =
19 {
20 {
21 buffer,
22 sizeof(buffer)
23 }
24 };
25
26 int i;
27
28 for (i = 0; i < 5; i++)
29 {
30 printf("%d\n", data[0].buffer);
31 }
32 printf("data size = %d\n", data[0].length);
33
34 return (EXIT_SUCCESS);
35
36 }