Assinging values to type float

Larry Jones scjones at thor.UUCP
Wed Sep 5 00:17:13 AEST 1990


In article <11583 at crdgw1.crd.ge.com>, volpe at underdog.crd.ge.com (Christopher R Volpe) writes:
> This raises a question I've been wondering about for a while: 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?       

An "expression" is defined by the C grammar.  No operators are
required, "i" is an expression as is "f1=f2" (note that "=" is
the assignment >operator< in C).  In fact "f1=f2" should cause
f2 to be widened to double and then narrowed back to float.
Fortunately, even very dump compilers are smart enough to
optimize out the spurious widening and narrowing operations.
----
Larry Jones                         UUCP: uunet!sdrc!thor!scjones
SDRC                                      scjones at thor.UUCP
2000 Eastman Dr.                    BIX:  ltl
Milford, OH  45150-2789             AT&T: (513) 576-2070
Start tying the sheets together.  We'll go out the window. -- Calvin



More information about the Comp.lang.c mailing list