Re: warning while making cast



"Roman Mashak" <mrv@xxxxxxxx> writes:
Hello, vippstar@xxxxxxxxx!
You wrote on Thu, 5 Jun 2008 04:27:18 -0700 (PDT):

v> The return value of sqrt is implicity converted to long.

In my understanding implicit conversion is a promotion of types, i.e.
without loss of bits. For instance, float to double
[...]

I'm afraid your understanding is incorrect.

The promotions that occur for operands of most operators are designed
not to lose information (at least in most cases(?)), but those aren't
the only implicit conversions that can occur. In an assignment or
equivalent (initialization, parameter passing), any arithmetic type
can be implicitly converted to any other arithmetic type. You can
even assign a long double to a char. No diagnostic is required,
though compilers are free to print warnings if they choose.

--
Keith Thompson (The_Other_Keith) kst-u@xxxxxxx <http://www.ghoti.net/~kst>
Nokia
"We must do something. This is something. Therefore, we must do this."
-- Antony Jay and Jonathan Lynn, "Yes Minister"
.



Relevant Pages

  • Re: warning while making cast
    ... In my understanding implicit conversion is a promotion of types, ... without loss of bits. ... v> the integral part cannot be represented by the integer type, ...
    (comp.lang.c)
  • Re: Array and Pointer Tutorial
    ... implicit conversion (e.g. char to int). ... there is no typical implicit conversion for your phrase ... "just like any other implicit conversion", to refer to. ... arithmetic type lower ranking than int, ...
    (comp.lang.c)