[Vm-dev] Removing UB to make SmallFloat handling gcc 4.9.2 -O2 compatible [WAS: first 64 bits windows VM Running]

Ben Coman btc at openinworld.com
Sat Jul 23 12:02:56 UTC 2016

Whoops I think I made a mistake.  All these negative opinions below
relate to struct / union interaction.  Presumably type-punning can
just use unions on their own with no structs.
cheers -ben

On Sat, Jul 23, 2016 at 7:20 PM, Ben Coman <btc at openinworld.com> wrote:
> I also found some negative opinions...
> "There may be unused holes in structures. Suspect unions used for type
> cheating. Specifically, a value should not be stored as one type and
> retrieved as another"
> [5] https://www.doc.ic.ac.uk/lab/cplus/cstyle.html
> And...
> "The riskiest form of packing is to use unions. If you know that
> certain fields in your structure are never used in combination with
> certain other fields, consider using a union to make them share
> storage. But be extra careful and verify your work with regression
> testing, because if your lifetime analysis is even slightly wrong you
> will get bugs ranging from crashes to (much worse) subtle data
> corruption."
> [6]http://www.catb.org/esr/structure-packing/
> And...
> "The problem with a structure inside a union, is that the compiler is
> allowed to add padding bytes between members of a structure (or
> class), except bit fields....[instead] suggest creating functions to
> combine and extract pixels from a 32-bit quantity. You can declare it
> inline too. This is a lot more reliable than a struct inside a union,
> including one with bit fields.
> [7] http://stackoverflow.com/questions/2876832/using-unions-to-simplify-casts

More information about the Vm-dev mailing list