- Joined
- May 1, 2017
- Messages
- 5
- Reaction score
- 3
I have the following snippet of C code lifted fro a large mass of legacy code. having managed to compile a 120 parts of various libraries, but I am stuck on this one extern problem my brains just starting to dry up.
Any one have a solution please.
Tn it's original form the snippet read:
A)
............
extern end;
unsigned Lastbrk = (unsigned) &end;
..............
This produced : "error: initializer element is not constant"
fair comment as end has only been declared, not been defined no memory allocated.
----------------------------------------------------------------------
I modified it to read :
B)
......................
extern int end = 0;
unsigned Lastbrk = (unsigned) &end;
........................
My reasoning is that, the C standard says (from memory): that if a variable is not only declared extern but an initializer is also provided with that declaration, then the memory for that variable will be allocated–in other words, that variable will be considered as defined.
But I still get "error: initializer element is not constant" Which is not true as end has been initalized so &(end) will have a known value ?
Is this a gcc bug or what? I am using an old gcc 4.7.2 but about to switch Sun_Workshop on Solaris 8.
any help appreciated,
OBB (Dave)
Any one have a solution please.
Tn it's original form the snippet read:
A)
............
extern end;
unsigned Lastbrk = (unsigned) &end;
..............
This produced : "error: initializer element is not constant"
fair comment as end has only been declared, not been defined no memory allocated.
----------------------------------------------------------------------
I modified it to read :
B)
......................
extern int end = 0;
unsigned Lastbrk = (unsigned) &end;
........................
My reasoning is that, the C standard says (from memory): that if a variable is not only declared extern but an initializer is also provided with that declaration, then the memory for that variable will be allocated–in other words, that variable will be considered as defined.
But I still get "error: initializer element is not constant" Which is not true as end has been initalized so &(end) will have a known value ?
Is this a gcc bug or what? I am using an old gcc 4.7.2 but about to switch Sun_Workshop on Solaris 8.
any help appreciated,
OBB (Dave)