Tuesday, November 20, 2018

[jonbxzup] Specify an integer type by what it does, not its name

Let a programmer specify in code an integer type as "the fastest machine integer type that covers at least this given range", and the compiler will pick one for you.  Note, however, this doesn't give you automatic run-time bounds checking, though you could get that as an additional library.  Maybe it does give you compile-time bounds checking.

Or, "the most compact" instead of "fastest" if optimizing for space instead of speed.

If you want specific wraparound overflow behavior or bit representation, specify a type explicitly; don't let the compiler choose one for you.

Floating point similarly, though it requires specifying both a desired precision and range.

No comments :