We are running a survey to help us improve the experience for all of our members. If you see the survey appear, please take the time to tell us about your experience if you can.
If in "normal" C, I define a global constant in one module:
const int iTabCount= 5;
and then use this constant in another module (module2.c) with extern:
extern const int iTabCount;
Then "normal" C will do this without any problems.
But in C++ files this fails, even if I encapsulate these definitions in extern "C" { ... };
If I use C++, in the first module, I get
warning #177-D: variable "iTabCount" was declared but never referenced
(This is correct, it is really not referenced in this module - but as this variable is NOT defined as static, there should be no problem ...).
And on linking I get the following error:
Error: L6218E: Undefined symbol iTabCount (referred from module2.c)
All works fine, if I remove the "const" qualifier. But I would like to keep it - especially for some larger const table, where it would be quite inefficient to reserve RW data space for such a code table.
I think this is some C++ compiler problem? Not possible to use const data over several modules in C++?
Ups - I am surprised. You are right - if I insert the
extern const int iAnzParTab;
into the header file (included into both modules), then all works fine.
Thank's a lot! (I tried it also with my table - I can also declare the "unknown size" table in this header file, and then give the specific size only in module2.cpp - that's exactly what I needed:)
extern const TAB aTab[];