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/TM4C123FH6PM: Constant structures in C++

Part Number: TM4C123FH6PM


Tool/software: TI C/C++ Compiler

Hello!

This simple example:

struct Test1 {
    const uint8_t t;
    const int i;
    const float f;

    Test1(int _i) : t(0), i(_i), f(0) {}
    Test1(float _f): t(1), i(0), f(_f) {}
};

const Test1 t1((int)12);
const Test1 t2((float)12.5);


should create const objects, as all fields are const and constructors are empty and just initializing fields, so this is compile-time definition (should be). In fact, after compilation during debug I see these objects are located in RAM, not FLASH, as I expect.

I need to define a constant array (large one) of such objects, so I need them in FLASH.

  • I tried a few different compilers.  TI and GCC.  ARM and not ARM.  None of them handle those const instances of the Test1 struct the same way they handle a simple const array.  So, through proof by direct experiment, I have unfortunately demonstrated that what you want to do is not supported.

    Thanks and regards,

    -George