Mail Archives: djgpp/1997/01/30/05:19:51
On Tue, 28 Jan 1997, Benjamin D Chambers wrote:
> >> function. Anyway, here's my problem; To my understanding the
> >following
> >> are 100% equal:
> >>
> >> other_stuff = stuff / 256;
> >> other_stuff = stuff << 8;
> >
> >The second multiplies. Try ">> 8" instead.
> >
> >
> Also, just to be clear, the first gets translated into the second when
> compiling with optimizations on (-O2).
> In fact, I believe *ALL* integer multiplication/division by a constant
> gets converted to shifts when using -O2, so you might as well use the
> first - if for nothing else then for readability's sake.
You cant be GUARANTEED that the code generated will be the shifted
version. What if a different C compiler is used? The only way to
ensure that you get the shifts is to code it that way. It may look
obscure, but a comment will fix that up.
other_stuff = stuff >> 8; /* stuff * 8 */
Mike A. Harris | http://blackwidow.saultc.on.ca/~mharris
Computer Consultant | My webpage has moved and my address has changed.
My dynamic address: http://blackwidow.saultc.on.ca/~mharris/ip-address.html
mailto:mharris AT blackwidow DOT saultc DOT on DOT ca
DJGPP: Current version 2.01
- Raw text -