2 ms·
I can't ever imagine a scenario where a hack _like_ _that_ is acceptable. If you need something like that, just drop down to assembly. It's more portable (in t
by wahern 10y ago
I can't ever imagine a scenario where a hack _like_ _that_ is acceptable.
If you need something like that, just drop down to assembly. It's more portable (in the sense that you're coding to an interface), infinitely more clear about what you're doing and and how you're doing it, much less likely to break, and when it does break is likely to break loudly.
Even if you've never done a lick of assembly programming (I haven't done much) it'd still be infinitely preferable, even if you had to support a dozen architectures with two dozen different function proxies.
"Hack" is a very broad term. By some definitions a significant chunk of extant code qualifies as a hack. But whatever the definition, a hack still implies some quantum of legitimacy. There's nothing legitimate in using function type punning as a way to reorder or control argument values. Not unless this was 1969, where there was precisely one C compiler, used by precisely one guy, and where such code was expected to be thrown out in short order, never to infect code that executed in other than identical circumstances.
- caf 10y agoThe reordering thing is bunk anyway, because if you just define the reordering function: double IntPowerOfDouble(int power, double base) { return DoubleToTheInt(base, power); } ...then gcc with -O1 will optimise IntPowerOfDouble to a plain "call DoubleToTheInt", and with -O2 will completely inline DoubleToTheInt into it.