casts and assignments

mbrennan at vax1.tcd.ie mbrennan at vax1.tcd.ie
Tue Dec 5 04:39:39 AEST 1989


In article <21033 at mimsy.umd.edu>, chris at mimsy.umd.edu (Chris Torek) writes:
> In article <6589 at arcturus> evil at arcturus.UUCP (Wade Guthrie) writes:
>>... I am led to believe that all assignments include an implicit cast
>>such that:
>>	a = (type of 'a') (expression);
>>Is exactly equivalent in ALL cases to:
>>	a = (expression);
>>Is this true?

int i ;
int j ;
long l ;

	l = i * j ;
	l = (long) i * j ;

I realise I may be answering a slightly different question than you posed, 
but ...

The above two statements will not yeild the same result, because in the 
first instance the int's i and j are multiplied and the result stored in 
an unnamed temp of type int.

In the second case however i is coerced to long first.  Then before
multiplication can take place j is promoted to the same type(long).  This
means the result of the multiplication is held in an unnamed temp of type long
thus ensuring no loss of significant digits.

 ,   ,
Micheal 

mbrennan at cs.tcd.ie



More information about the Comp.lang.c mailing list