Implicit and explicit conversion

F

/* frank */

Explicit conversion is made by mean of a cast
i.e.

float a;
int b;
....
b = (int) a;

But the implicit conversion? What is?
 
M

Mike Wahler

/* frank */ said:
Explicit conversion is made by mean of a cast
i.e.

float a;
int b;
...

I'll assume that 'a' and 'b' have been initialized
with or assigned values.
b = (int) a;

But the implicit conversion? What is?

Without a cast.

=============================================================
ISO/IEC 9899:1999 (E)

6.3 Conversions

1 Several operators convert operand values from one type to
another automatically. This subclause specifies the result
required from such an implicit conversion, as well as those
that result from a cast operation (an explicit conversion).
The list in 6.3.1.8 summarizes the conversions performed by
most ordinary operators; it is supplemented as required by
the discussion of each operator in 6.5.

2 Conversion of an operand value to a compatible type causes
no change to the value or the representation.
=============================================================


/* implicit conversions (using your definitions above): */

b = a;
a = b;

-Mike
 
M

Martin Ambuhl

/* frank */ said:
Explicit conversion is made by mean of a cast
i.e.

float a;
int b;
...
b = (int) a;

But the implicit conversion? What is?

Are you ready?
b = a;
Hard, ain't it?
 
D

Dan Pop

In said:
Explicit conversion is made by mean of a cast
i.e.

float a;
int b;
...
b = (int) a;

But the implicit conversion? What is?

Exactly what the name says: a conversion performed by the compiler
automatically (without requiring a cast).

Examples: the integral promotions, the usual arithmetic conversions,
the default argument promotions, calling a function with a prototype
declaration in scope, when the types in the function call don't
match the types in the function declaration, the return statement,
the assignment operator.

Examples (using your declarations above):

b = a + 1; /* two examples in this statement */
printf("%f\n", a);
fseek(fp, 0, SEEK_SET);
int main() { return 0.0; }

Dan
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,764
Messages
2,569,567
Members
45,041
Latest member
RomeoFarnh

Latest Threads

Top