Difference between typecasting and casting

N

Nishu

Hi all,

What is difference between typecasting and casting? I used to think
that both are same; but few days back someone pointed out here that
these are different. Vague guess, Is it that typecasting means casting
using typedef? I just want to confirm it.

Thanks,
Nishu
 
G

Guest

Nishu said:
Hi all,

What is difference between typecasting and casting? I used to think
that both are same; but few days back someone pointed out here that
these are different. Vague guess, Is it that typecasting means casting
using typedef? I just want to confirm it.

The official term is a cast. An unofficial term is a typecast. I'm not
aware of any other differences.
 
R

Richard Heathfield

Nishu said:
Hi all,

What is difference between typecasting and casting?

A cast is an explicit conversion, so casting is the act of performing an
explicit conversion. For example, int *p = &i; printf("%p\n", (void
*)p); explicitly converts p into a void * to make it suitable for
matching the %p format specifier.

Typecasting, on the other hand, is what happens to an actor when they're
given the same kind of part over and over. For example, Christopher Lee
always seems to get to be the villain.
 
S

santosh

Nishu said:
Hi all,

What is difference between typecasting and casting? I used to think
that both are same; but few days back someone pointed out here that
these are different. Vague guess, Is it that typecasting means casting
using typedef? I just want to confirm it.

I think, in C atleast, the more precise term is cast. The act of
making a cast is called casting. It's often used only for explicit
casts, i.e. those that you explicitly write in the source. Implicit
casts, i.e. those that happen due to the rules of C for evaluating
expressions, are probably better called as implicit conversions.
 
K

Keith Thompson

santosh said:
I think, in C atleast, the more precise term is cast. The act of
making a cast is called casting. It's often used only for explicit
casts, i.e. those that you explicitly write in the source. Implicit
casts, i.e. those that happen due to the rules of C for evaluating
expressions, are probably better called as implicit conversions.

I would state it more strongly than that. A cast is an operator that
explicitly specifies a conversion. There are implicit conversions,
but there's no such thing as an "implicit cast".
 
J

Jack Klein

I think, in C atleast, the more precise term is cast. The act of
making a cast is called casting. It's often used only for explicit
casts, i.e. those that you explicitly write in the source. Implicit
casts, i.e. those that happen due to the rules of C for evaluating
expressions, are probably better called as implicit conversions.

I know that Keith already responded, but I don't think he was detailed
enough.

C allows conversions of some types to others. Some of these
conversions are automatic, happening in the course of evaluating an
expression, performing an assignment, or passing an argument to a
prototyped function. Other casts require the use of a cast operator.

Since the only thing that performs a cast is a conversion operator,
all casts are explicit. There is no such thing as an "implicit cast",
but there is an "implicit conversion".

The first sentence of 6.3 Conversions of the C standard describes this
concisely:

"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)."
 
S

Serve Laurijssen

Richard Heathfield said:
Nishu said:


A cast is an explicit conversion, so casting is the act of performing an
explicit conversion. For example, int *p = &i; printf("%p\n", (void
*)p); explicitly converts p into a void * to make it suitable for
matching the %p format specifier.

Typecasting, on the other hand, is what happens to an actor when they're
given the same kind of part over and over. For example, Christopher Lee
always seems to get to be the villain.

hahaha, here i thought there was a difference
 

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

Forum statistics

Threads
473,769
Messages
2,569,580
Members
45,054
Latest member
TrimKetoBoost

Latest Threads

Top