I have the following piece of code, that works with gcc 4.3 compiler, but when I compiled with gcc 4.8, got resolved symbol error ( linking time)
//test.cc
ULONG CPULimit = 200;
// test.h
namespace ABC
{
class STAT
{
public:
static ULONG getCPULimit();
}
}
in the same test.h file itself, I have defined the getCPULimit() function inline
inline ULONG
ABC::STAT::getCPULimit()
{
extern ULONG CPULimit;
return CPULimit;
}
The above code worked with 4.3 compiler, with 4.8 got unresolved symbol error.
moving extern ULONG CPULimit outside the function, will work but it exposes the global variable. now I wrapped the function with extern "C" like this
extern "C"
{
inline ULONG
ABC::STAT::getCPULimit()
{
extern ULONG CPULimit;
return CPULimit;
}
}
and surprisingly it worked, 1) I'm not sure how it worked , could anyone shed some light? Is this the right way of doing it?
2) what does it mean to have two externs (one extern C and one extern)