to co tutaj robisz to jest UB. Nazwy zaczynające się od podłogaWIELKALITERA są zarezerwowane dla implementacji. Odnoszenie się do danych za poprzez wskaźnik do innego typu, poza specjalnymi przypadkami, jest zabronione.
O tym, że nie może używać wielkich liter po podłodze, to nie wiedziałem, ale z drugim się nie zgodzę, bo jest to powszechnie spotykanie w C. Można by było jedynie użyć int32_t zamiast int.
Możesz się nie zgadzać ile chcesz, to nic nie zmienia.
Standard C++ (n3797), §3.10/10 napisał(a)
If a program attempts to access the stored value of an object through a glvalue of other than one of the following types the behavior is undefined:
— the dynamic type of the object,
— a cv-qualified version of the dynamic type of the object,
— a type similar (as defined in 4.4) to the dynamic type of the object,
— a type that is the signed or unsigned type corresponding to the dynamic type of the object,
— a type that is the signed or unsigned type corresponding to a cv-qualified version of the dynamic type of the object,
— an aggregate or union type that includes one of the aforementioned types among its elements or nonstatic data members (including, recursively, an element or non-static data member of a subaggregate or contained union),
— a type that is a (possibly cv-qualified) base class type of the dynamic type of the object,
— a char or unsigned char type.
§4.4 odnosi się do zmiany kwalifikatorów (const
/volatile
)
Pomimo, że wątek ma w tagu c++
, sprawdziłem też jak sprawa wygląda w C:
Standard C (n1570), §6.5/7 napisał(a)
An object shall have its stored value accessed only by an lvalue expression that has one of the following types:
— a type compatible with the effective type of the object,
— a qualified version of a type compatible with the effective type of the object,
— a type that is the signed or unsigned type corresponding to the effective type of the object,
— a type that is the signed or unsigned type corresponding to a qualified version of the effective type of the object,
— an aggregate or union type that includes one of the aforementioned types among its members (including, recursively, a member of a subaggregate or contained union), or
— a character type.
Inaczej mówiąc, sam fakt, że coś jest powszechnie spotykane nie czyni tego poprawnym.