[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

Re: sqrt C function



Paul Scott wrote:

> I doubt if this is your problem but on most compilers:
> 
>     double num;
> 
>     num = 4;
> 
> is inefficient;  It normally causes an integer constant 4 to be stored 
> somewhere.  Then when num = 4;  is executed the integer 4 is converted 
> to double every you execute the code.

That might have been true of C compilers 20 years ago, but I doubt it's
true today. gcc is probably smart enough to realize that when a literal
constant being assigned to a variable, that the constant should be of
the same type as the variable.

Similarly, it isn't true anymore that "while (1)" is less efficient than
"for (;;)", which, 20 years ago, was true on some compilers; for "while
(1)", they would actually generate a silly test like, "Load a register
with 1, compare the register to zero, jump if equal" -- which,
obviously, always failed. I haven't seen that in a long, long time.

Craig



Reply to: