We have a piece of c-code in our system that includes some of the arrays with Global Access:
source.h
External Contint Magic [5];
source.c:
const int magic [] = {1, 2, 3, 4, 5}; Someone decided that it would be a good idea to convert it to C ++ and extern "c"
block: P> Source.h: extract "c" {concrete magic [5]; }
source.cc:
extern "c" {const int magic [=] {1, 2, 3, 4, 5}; }
It is compiled without a thing with GCC-VALIDITY
It was not until someone tried to use that array Who has discovered the problem for us. Inside an extern "c"
inside an const
, no external symbol is generated, it happens with the GCC, Sun Workshop and IBM Compiler.
I am about to some degree of damage that it is expected behavior, given that GCC does not warn you that you are doing something strange.
Is this behavior to be specified by the standard, or is this a comprehensive bug?
const
variable has an internal relationship (as declared constant
) Unless you use extern
to specify external linkage if you want to define it in a source file and get it from other people, then you External relation will be required.
To specify this language linkage, extern "C"
.
Extra "C" {External Contint Magic [5]; }
Your announcement is correctly specified external link; But when you turned to C ++, you deleted it.
Comments
Post a Comment