If you count RFCs as standards there are probably lots more examples of this.
>> on signed is implementation-defined, not undefined, and fairly safe to rely upon. << on negative is undefined. Overflow is always undef.
-
-
When x is signed, x<<n is equivalent to x*(1<<n) except the former is defined on a smaller domain; just use the latter if you care.
-
usually << on signed is functionally equivalent to the unsigned case. some targets also have expensive '*' (if not optimized away).
-
If a compiler can't generate "SHL n" for "*(1<<n)" it's not suitable for real-world use. You write C to the language, not to a bad compiler.
-
I have seen CC's which would fail to optimize this, for targets with neither a "SHL n" op, nor a "MUL" op, so both end up as runtime calls.
-
If this optimization or lack thereof happens at the target backend level rather than on high-level IR, the compiler is hopelessly broken.
-
I am thinking it is going pretty ok if the CC's work and accept modern'ish C syntax (luckily K&R only CC's are pretty much dead now...).
-
You're a decade or two late on these discussions...
-
old stuff lingers for a while, it seems only pretty recent that using GCC/etc became semi-universal (vs LCC variants and one-off compilers).
- 1 more reply
New conversation -
Loading seems to be taking a while.
Twitter may be over capacity or experiencing a momentary hiccup. Try again or visit Twitter Status for more information.