Getting started

Thomas Heller thomas.heller at ion-tof.com
Thu Sep 26 09:25:00 EDT 2002


Alex Martelli <aleax at aleax.it> writes:

> James J. Besemer wrote:
>         ...
> > Types are otherwise pretty secure in C++ except the "cast" mechanism
> > "foils" the type system and thus allows type errors to occur.
> 
> Actually, unions are at least as bad -- they're not often used
> for type-punning because casts are handier for that, but if you
> took cast aways, people would (ab-)use unions (just like they
> abuse EQUIVALENCE in Fortran for similar purposes).
> 
> Technically I believe that in C++ (not sure about the two ISO
> C standards -- I'm more definite that this was the case in
> Fortran-77 and I believe in Fortran-IV too) storing one union's
> member then retrieving another one puts your program in
> undefined-behavior land.  In practice, I know of no existing
> compiler that goes to the bother of checking (e.g. by storing
> a hidden tag when you store into a union and checking whenever
> you retrieve from it -- even harder if you consider _pointers_
> to the various members of the union).

Hidden fields in a union by the discretion of the compiler?
Don't think that would be allowed by any C standard.

Thomas



More information about the Python-list mailing list