C++ Memory Address of const class instances

Asked by Gergely Budai

If i have a simple class instance like this:

class Test
{
  public:
    void Print(void) const
    {
      printf("Test");
    }
};
const static Test test;

And later somewhere I refer the address of that object like:
printf("Address: %X", &test);

Then I can see in the map file that the compiler reserves one byte for that address in the .bss segment:
.bss._ZL4test 0x20005308 0x1

I would assume that for something simple like this the compiler would reserve space in the .text segment which does not cost any RAM space.

Is there any way to tell g++ to put the address of such objects (without any member variables) into the FLASH instead of RAM?

(GCC 6 2017-q2-update on CORTEX-M4)

Question information

Language:
English Edit question
Status:
Expired
For:
GNU Arm Embedded Toolchain Edit question
Assignee:
No assignee Edit question
Last query:
Last reply:
Revision history for this message
Launchpad Janitor (janitor) said :
#1

This question was expired because it remained in the 'Open' state without activity for the last 15 days.

Revision history for this message
Gergely Budai (gbudai76) said :
#2

The solution is:

Add a constexpr constructor.

This way the object instance will be put into the .rodata segment.