LINUX.ORG.RU

История изменений

Исправление gentoo_root, (текущая версия) :

А ещё если бы это был C++, а не C, то было бы ещё и неопределённое поведение там, где мы сначала записываем в u.in, а потом вычитываем u.out.

In a union, at most one of the non-static data members can be active at any time, that is, the value of at most one of the non-static data members can be stored in a union at any time.

А в C это работает:

If the member used to read the contents of a union object is not the same as the member last used to store a value in the object, the appropriate part of the object representation of the value is reinterpreted as an object representation in the new type as described in 6.2.6 (a process sometimes called ‘‘type punning’’).

Большинство компиляторов ведут себя так же и в C++, однако не компилятор от Sun, например.

Исходная версия gentoo_root, :

А ещё если бы это был C++, а не C, то было бы неопределённое поведение там, где мы сначала записываем в u.in, а потом вычитываем u.out.

In a union, at most one of the non-static data members can be active at any time, that is, the value of at most one of the non-static data members can be stored in a union at any time.

В C это точно работает:

If the member used to read the contents of a union object is not the same as the member last used to store a value in the object, the appropriate part of the object representation of the value is reinterpreted as an object representation in the new type as described in 6.2.6 (a process sometimes called ‘‘type punning’’).

Большинство компиляторов ведут себя так же и в C++, однако не компилятор от Sun, например.