1

I'm using VS 2019 with VisualGDB extension for STM32F303VC device. I have a class TlteCom with array of pointers to members of the C++ 17 class. Here it is:

class TlteCom
 {
  public:
   volatile uint16_t number=0;
   volatile uint16_t paramNumber=0;
   volatile char param1[20];
   volatile char param2[20];
   volatile char param3[8];

   constexpr static uint8_t paramCount = 3;
   volatile char *const paramlist[paramCount] = {(volatile char *)param1, (volatile char *)param2, 
                                                 (volatile char*)param3};
   volatile uint16_t paramlength[paramCount] = { 0, 0, 0 };
 };

I create the object of the class as global variable as follows: TlteCom com;

I don't understand why com.paramlist members are all zero. if I create object of the TlteCom class on stack in main() function everything is ok: com.paramlist has right values of param1, param2, param3 addresses. So, what is the right initialization of pramlist array?

Joel Bodenmann
  • 2,152
  • 2
  • 17
  • 44
igor.k
  • 31
  • 6
  • Can't reproduce: https://godbolt.org/z/b9zuq_ – Ted Lyngmo Mar 08 '20 at 10:12
  • The members of `com.paramlist` are not all zero: [I get different values](http://coliru.stacked-crooked.com/a/77f4902da3d36294). – einpoklum Mar 08 '20 at 10:12
  • 1
    Possibly a bug in the `STM32F303VC` compiler? – Alan Birtles Mar 08 '20 at 10:14
  • Please add the missing code ([mcve]), how do you create the object and how do you know that the pointers are all zero? – 463035818_is_not_an_ai Mar 08 '20 at 10:14
  • Also, be sure you don't want [member pointers](https://stackoverflow.com/questions/670734/pointer-to-class-data-member) into Tltecom instances rather than plain pointers. – einpoklum Mar 08 '20 at 10:15
  • Also , if i use 'constexpr static char param1[20], param2[20] ,param3[8]' and 'constexpr static char * paramlist[]={(char*) param1,(char*) param2,(char*) param3}' everything is ok! – igor.k Mar 08 '20 at 10:33
  • @Ted Lyngmo I tried to use them (backticks). Explain, please, why the code sentence is not grey. – igor.k Mar 08 '20 at 10:40
  • 1
    @Ted Lyngmo Thank u. I understood. `code` – igor.k Mar 08 '20 at 10:45
  • Thanks! The problem was solved! I forgot to call constructors from startup code. The following may be usefull for someone: `extern void(*__init_array_start)(); extern void(*__init_array_end)(); for (void(**p)() = &__init_array_start; p < &__init_array_end; p++) (*p)();` – igor.k Mar 08 '20 at 20:20

0 Answers0