"peter koch" <pe***************@gmail.comwrote in message
news:11*********************@m73g2000cwd.googlegro ups.com...
>
Thierry Lam skrev:
>What does the following macro mean, especially the << sign:
#define hello(x) (( int64 ) floor( (double) x ) << 32)
Thanks
Thierry
In C++, << is normally the stream-operator - used e.g. for outputting
variables. In low-level code it can also be used for bitshifting -
which previously was used sometimes for optimising
multiplication/division. Today, you gain nothing in speed and you
should avoid usage of the operator for stuff of this type.
In the example above, to the best of my knowledge the result of the
macro is undefined as shifts of an int64 is implementation-defined. (Of
course - so is int64).
Bit shifting is not obsolete, or unnormal, by any means. It's not always an
attempt at speeding up multiplication. Sometimes it is used as a portable
way to read bytes whose order might differ between platforms. The results
are guaranteed, regardless of endian-ness (provided they're used on integral
types for which the results are defined, naturally).
It's also used for bit-masking, allowing you store more information in one
location.
Also, if shifts of an int64 is implementation-defined, then the result of
the above macro is also implementation-defined, not undefined. There's a
difference.
-Howard