Joe Wright wrote:
Barry Schwarz wrote:
>On Mon, 18 Jun 2007 20:28:36 -0400, Joe Wright
<jo********@co mcast.netwrote:
>>Shraddha wrote:
I got a small programm on net...but there was different initialisation
that I saw...
It was as follows:
for ( i = ~0 ; i ; i>>=1);
right shift is ok..But what is meaned by " i = ~0 "...
Same as "i = -1;" I suppose.
Not on a 1's complement or a signed magnitude machine.
Of course but these machines imaginary aren't they?
Of course they are. Completely imaginary. And THAT'S
why the committees who wrote and revised the Standards made
allowance for them. Even when they tightened the allowable
representations in C99, they still allowed ones' complement
and signed magnitude. Simply decreeing two's complement
would have made a lot of things simpler, but the committees
were made up entirely of masochists who loved to make trouble
for themselves. That's why you needn't worry your pretty
little head about it: All the world is a two's complement
32-bit Little-Endian IEEE-floating-point dosbox, and don't
let anyone tell you any different.
Or to put it another way: A friend of mine likes to say
that computing is a fashion-driven industry. Fashions come,
and fashions go, and fashions come again. You can write your
program for this season's hem lines and color schemes, or you
can attempt something a little less transitory. There are,
after all, some distinct infelicities in two's complement:
the fact that abs(n) cannot be implemented reliably stands
out as an ugliness that neither of the alternatives suffer
from, and tomorrow's system couturier may reject that ugliness.
Trap representations for integers are Out today, but in the
face of viral onslaught might not tomorrow's machine revive
the old practice of explicitly-typed data?
Sometimes it doesn't make sense to sacrifice all other goals
on the altar of portability: Portability is just one among many
desirable attributes of a program. But there are *very* few
reasons to engage in gratuitous importabilities like those(?)
in the above code example. You may not particularly like the
ruffles-with-polka-dots theme that all the designers will put
on the runways next year, but it costs you little or nothing
to accommodate it -- and if you don't, none of the hot models
will wear your code.
--
Eric Sosman
es*****@acm-dot-org.invalid