This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

Compiler/TMS320F28377S: compiler

Part Number: TMS320F28377S

Tool/software: TI C/C++ Compiler

Hi,

I have a question about compiler in version TI v6.4.6 that a pragma-retained global constant is removed by the optimization.

Here's the global constant variable declaration

#pragma RETAIN
#pragma DATA_SECTION("DeviceId")
const unsigned long DEVICE_ID = 0xB3B3B3B3;

and the linker script

DeviceId: > DEVICE_INFO, PAGE = 7

But, I can't find there's any data being allocated to section DEVICE_INFO in the .map file.

That variable will not be used explicitly in the code, but just serves as a stamp.

Thanks.

  • In C++, const variables have internal linkage by default.  (See The C++ Programming Language, 3rd Edition, section 9.2).  This means they are static.  The compiler does not emit a static variable which is not used within the file.  The easiest way to overcome it is by adding the keyword extern.

    extern const unsigned long DEVICE_ID = 0xB3B3B3B3;

    Thanks and regards,

    -George