Problem in type conversion

addw at root44.UUCP addw at root44.UUCP
Thu Jan 19 16:19:51 AEST 1984

<<<<<To be eaten by mailers>>>>>
Roger L. Ferrel said:

>> What we see here with the:
>> 	inttype *= 0.5;
>> 		vs
>> 	inttype = inttype * 0.5;
>> is a weekness of most C compilers. It seems none of them handles float
>> operations very well when there are mixed types.  Of course the above is
>> a poor example since normally more efficent code would be generated by
>> using:
>> 	intype >>= 1;  /* how is this for getting off the subject? */

Unfortunately this is only guaranteed to work if:
1)	inttype is unsigned -plainly not the intention.
2)	inttype is positive, if inttype is negative it is undefined
what is put into the top bit; ie your negative number may become positive.
(A '1' will be inserted on a PDP11, but I assume that it is intended to write
portable programs. I don't know what other machines will do.)

There is little point in being efficient but wrong.
The only real alternative is:
	inttype /= 1;

	Alain Williams
	Root Computers Ltd, London.

PS, In England we spell the word that means 'lack of strength' as weakness,
& efficent as efficient.

More information about the Comp.lang.c mailing list