lua-users home
lua-l archive

[Date Prev][Date Next][Thread Prev][Thread Next] [Date Index] [Thread Index]

> Just another data point, since I recently saw it:
> The well-used GLM library (which is C++) uses type punning through a
> union just about as clear as can be:
> I suppose, since it's C++ (not C90), it is technically undefined
> behavior. But I have certainly worked on dozens of systems over
> decades that rely on it, so it seems like extremely reliable undefined
> behavior, as far as that goes (:  And of course, it is explicitly
> supported by GCC.

I just learned that C99 was amended about that, to make clear that this
kind of tricks with unions behave as expected [1]. It now includes
the following footnote in

    82) If the member used to access 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").
    This might be a trap representation.

(My version of the standard does not have these amendments.)


-- Roberto