Conversions and casts

D

Daz

Hi everyone!

I am very new to casting and converting, so much in fact then when I
think I have it figured out, something proves me wrong. I was wondering
if there is any logic in 'what types can be converted/casted into what
other types'. How do I know what casts I can use on a char array for
example. Is it something you just have to figure out, need to learn, or
is there somewhere that maybe most possible conversions are documented.
I have a number of casts that I'd like to make, but instead of posting
all of them, I'd rather know how to do it rather than have someone do
it for me.

Any input would be greatly appreciated.

Daz
 
O

osmium

Daz said:
I am very new to casting and converting, so much in fact then when I
think I have it figured out, something proves me wrong. I was wondering
if there is any logic in 'what types can be converted/casted into what
other types'. How do I know what casts I can use on a char array for
example. Is it something you just have to figure out, need to learn, or
is there somewhere that maybe most possible conversions are documented.
I have a number of casts that I'd like to make, but instead of posting
all of them, I'd rather know how to do it rather than have someone do
it for me.

The best starting point I know if is Appendix 6 in K&R's book on p 197 which
discusses conversions and promotions. Casting is something you do when the
things discussed there do not cover the case at hand.
 
P

pancham

Daz said:
Hi everyone!

I am very new to casting and converting, so much in fact then when I
think I have it figured out, something proves me wrong. I was wondering
if there is any logic in 'what types can be converted/casted into what
other types'. How do I know what casts I can use on a char array for
example. Is it something you just have to figure out, need to learn, or
is there somewhere that maybe most possible conversions are documented.
I have a number of casts that I'd like to make, but instead of posting
all of them, I'd rather know how to do it rather than have someone do
it for me.

Any input would be greatly appreciated.

Daz

When it comes to C++, conversions and casts is much more than what it
is in C. Leaving aside all the explicit casting paradigms, there could
be some many scenarios where compiler may do the implicit casting or
conversion for you. There are few items in "More Effective C++" by
Scott Meyers which explains few of them in detail.

~pancham
 
D

Daz

D

Daz

osmium said:
The best starting point I know if is Appendix 6 in K&R's book on p 197 which
discusses conversions and promotions. Casting is something you do when the
things discussed there do not cover the case at hand.

My text book collection is getting bigger by the day. Sooner or later I
will have the ultimate collection! Thanks osmium
 

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

Similar Threads

Incompatible type casts 8
Casts 81
Integer promotions, conversions, coercions and templates :( 39
conversions 5
Some Basics - strings and Conversions 7
Signed / Unsigned Conversions 0
casts 105
function casts 27

Members online

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,012
Latest member
RoxanneDzm

Latest Threads

Top