( persicsb | 2021. 04. 09., p – 11:35 )

Nem definiált a működés, csak akkor, ha lock-free atomic változók, vagy volatile sig_atomic_t típusú változók.

"When the processing of the abstract machine is interrupted by receipt of a signal, the values of objects that are neither lock-free atomic objects nor of type volatile sig_atomic_t are unspecified, as is the state of the floating-point environment. The value of any object modified by the handler that is neither a lock-free atomic object nor of type volatile sig_atomic_t becomes indeterminate when the handler exits, as does the state of the floating-point environment if it is modified by the handler and not restored to its original state."

Ez a C11 szabvány legutolsó ingyenesen elérhető draft verziójából van.

Forrás: http://www.open-std.org/jtc1/sc22/WG14/www/docs/n1570.pdf 5.1.2.3 Program execution fejezet.

 

Ami fontos még itt, az a volatile szemantikája. Erről ezt írja a szabvány a 6.7.3 Type qualifiers fejezetben:
An object that has volatile-qualified type may be modified in ways unknown to the implementation or have other unknown side effects. Therefore any expression referring to such an object shall be evaluated strictly according to the rules of the abstract machine, as described in 5.1.2.3. Furthermore, at every sequence point the value last stored in the object shall agree with that prescribed by the abstract machine, except as modified by the unknown factors mentioned previously.134) What constitutes an access to an object that has volatile-qualified type is implementation-defined.

 

Szóval amit elmondtál, az undefined, az adott platform adott fordítója dönti el, hogy mit csinál. A C nyelv nagyon aluldefiniált ilyen értelemben szemantikailag, rengeteg a nemdefiniált, illetve szabvány szerint implementációfüggő viselkedés.