0

I have been experimenting with the binaries generated with the ARM GCC compiler (Version 9.2.1). I noticed that even if I compiled the program with C++14 support, the lenient rules for POD types in are not used to put the struct definition in the rodata section.

For example:

struct DigitalOut 
{
   uint32_t port;
   uint32_t pin;
   uin32_t output_type;
   uint32_t output_speed;
}

This version is put in the rodata section if instantiated using brace initializers.

However if I introduce the specific constructor for the struct as show below, then its not put in the rodata section

struct DigitalOut 
{

   DigitalOut() = default;

   DigitalOut(uint32_t port, uint32_t pin) : 
   port{port},
   pin{pin},
   output_type{500}  //just an example
   output_speed{400} {}

   uint32_t port;
   uint32_t pin;
   uin32_t output_type;
   uint32_t output_speed;
}

What am I missing here? I am pretty sure I understand the C++'s updated definition for POD types, Trivially constructible and copyable classes and Standard layouts.

Link to the answer related to updated definiton POD types

Edit:

My question is regarding why would the compiler not able to do this? Could this be a missing feature in the compiler or am I doing something wrong?

user9191063
  • 1
  • 1
  • 1
  • POD rules are about what's acceptable in the C++ language. Whether a struct is compiled to the rodata section has nothing to do with the C++ language. It's a compiler issue. – john Mar 22 '20 at 09:35
  • @john agreed, but I originally intended to ask the question about the compiler too. I edited the question to make it clearer what I was asking. – user9191063 Mar 22 '20 at 09:53

0 Answers0