473,386 Members | 1,803 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

Difference between typecasting and casting

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

Feb 16 '07 #1
6 3186
Nishu wrote:
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.

Feb 16 '07 #2
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.

--
Richard Heathfield
"Usenet is a strange place" - dmr 29/7/1999
http://www.cpax.org.uk
email: rjh at the above domain, - www.
Feb 16 '07 #3

Nishu wrote:
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.

Feb 16 '07 #4
"santosh" <sa*********@gmail.comwrites:
Nishu wrote:
>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.
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".

--
Keith Thompson (The_Other_Keith) ks***@mib.org <http://www.ghoti.net/~kst>
San Diego Supercomputer Center <* <http://users.sdsc.edu/~kst>
We must do something. This is something. Therefore, we must do this.
Feb 16 '07 #5
On 16 Feb 2007 04:01:14 -0800, "santosh" <sa*********@gmail.comwrote
in comp.lang.c:
>
Nishu wrote:
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.
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)."

--
Jack Klein
Home: http://JK-Technology.Com
FAQs for
comp.lang.c http://c-faq.com/
comp.lang.c++ http://www.parashift.com/c++-faq-lite/
alt.comp.lang.learn.c-c++
http://www.contrib.andrew.cmu.edu/~a...FAQ-acllc.html
Feb 17 '07 #6

"Richard Heathfield" <rj*@see.sig.invalidwrote in message
news:C-******************************@bt.com...
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.
hahaha, here i thought there was a difference
Feb 17 '07 #7

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: Kapil Khosla | last post by:
Hi, I have been trying to understand this concept for quite sometime now somehow I am missing some vital point. I am new to Object Oriented Programming so maybe thats the reason. I want to...
3
by: Robert Street | last post by:
Hi! I'm rather new at c++ and I'm totally confused with this kind of typecasting: typedef signed char int8_t; typedef signed short int16_t; typedef struct broadcast_hdr {
4
by: Niklaus | last post by:
Hi, I would like to know more about casts.What exactly happens when casts are applied to a variable.I know that if an object of type int is applied an cast of float the result would be of type...
63
by: andynaik | last post by:
Hi, Whenever we type in this code int main() { printf("%f",10); } we get an error. We can remove that by using #pragma directive t direct that to the 8087. Even after that the output is...
16
by: Abhishek | last post by:
why do I see that in most C programs, pointers in functions are accepted as: int func(int i,(void *)p) where p is a pointer or an address which is passed from the place where it is called. what...
8
by: Mark Fink | last post by:
I try to port a server application to Jython. At the moment I use Jython21\Lib\socket.py Currently I do face problems with casting the string "localhost" to the desired value:...
5
by: WittyGuy | last post by:
How to typecast a "function pointer" to "const void*" type in C++ way? int MyFunction (double money); // Function prototype const void* arg = (const void*)MyFunction; // type casting...
12
by: bwaichu | last post by:
What is the best way to handle this warning: warning: cast from pointer to integer of different size I am casting in and out of a function that requires a pointer type. I am casting an...
11
by: weg22 | last post by:
Hi all, I'm having problems trying to type cast in VB.Net. I'd like to read in a 16 bit unsigned integer and convert it to a signed 16 bit integer. I'm using the following line of code: Dim...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.