Assinging values to type float

Stephen Clamage steve at taumet.com
Wed Sep 5 04:23:06 AEST 1990


volpe at underdog.crd.ge.com (Christopher R Volpe) writes:

|When we say that a float (or char) gets converted to a double (or int) in
|an expression, what exactly constitutes an expression? Is a single
|value on the RHS of an assignment operator an "expression" for
|conversion purposes? Or is at least one operator required? If
|I do a "f1=f2", does it first convert f2 to double and then back 
|to float in order to do the assignment? How about "c1=c2" for chars?       

In C, assignment is not necessarily a statement, as in some other languages.
Assignment is accomplished by the '=' operator, and the assignment is an
expression like any other.  Section 3.3.16 (and its subsections)
describe precisely what happens.  Briefly, the value of the rhs is
converted to the type of the lhs and the assignment is performed.

As to whether multiple conversions are performed, the "as-if" rule applies.
In principle, integral promotions and other specified conversions are
performed (e.g., char to int) and the result converted to the type of the
lhs.  If this turns out to be identical in result to just copying the value,
it is sufficient to copy the value.
-- 

Steve Clamage, TauMetric Corp, steve at taumet.com



More information about the Comp.lang.c mailing list