For the one to ask your question, wrote a trivial structure

struct Test { const static size_t sz = sizeof(system("")); char s[sz]; // первое системное слово char ss; // второе системное слово Test() : ss('?') { for (size_t i = 0; i < sz - 1; ++i) s[i] = 'a' + 1; s[sz] = sz + '0'; //инициализирую второе системное слово } }; 

In principle, in the structure, I initialize the symbol by going out of the array.

Now the question is: Is this UB specifically for this definition? And if my ss symbol takes the value that I assigned to s[sz] , then on other systems there may be another principle of field alignments?

  • four
    Actually intolerable. You cannot rely on this or that location of variables in memory. Alignment can be used or whatever else - in short, it is impossible to rely on the fact that the fields in the memory will be located in this way and not otherwise. - Harry
  • @Harry, Everything is very clear. - AR Hovsepyan
  • one
    @ARHovsepyan, do you seriously assume that the prototype of the int system(const char *) can change or thus determine the size of the int type? - avp
  • @avp, if you mean sizeof (system ("")), then this should be the size of type int on this machine. It's just an improvisation - AR Hovsepyan
  • @avp is the same as writing intrator_traits <int *> :: pointer instead of int *. Sometimes such a record on the buzz just - AR Hovsepyan

0