473,498 Members | 1,956 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Conversions and casts

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

Jun 8 '06 #1
5 1617
"Daz" writes:
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.
Jun 8 '06 #2

Daz wrote:
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

Jun 8 '06 #3
"pancham" <pa***********@gmail.com> writes:

Daz wrote:
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'.

I think Stroustrup says in his main book that there are maybe too many
implicit conversions in C++.
By chance I've just put together a sort of quiz on the topic at
http://www-h.eng.cam.ac.uk/help/tpl/...ongtyping.html
Slightly heavier stuff is at
http://www-h.eng.cam.ac.uk/help/tpl/...+/casting.html

Jun 9 '06 #4
Daz

Tim Love wrote:
I think Stroustrup says in his main book that there are maybe too many
implicit conversions in C++.
By chance I've just put together a sort of quiz on the topic at
http://www-h.eng.cam.ac.uk/help/tpl/...ongtyping.html
Slightly heavier stuff is at
http://www-h.eng.cam.ac.uk/help/tpl/...+/casting.html


Thanks for that Tim! I have also gone back a page on the website and
found a whole wealth of useful stuff. Very much appreciated. :)

Jun 10 '06 #5
Daz

osmium wrote:
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

Jun 10 '06 #6

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

Similar topics

2
1677
by: Mason Verger | last post by:
Given: int center = 0; int range = 5; int lower = 0;
10
2191
by: vb | last post by:
Hi all, I am a newbie in C and i want to know what all pointer conversions are "legal" according to ANSI C standard. For Example, int* to char*, some_struct* to char* and so on .. According to...
31
3561
by: Michael C | last post by:
If a class inherits from another class, say Form inherits from control, then I can assign the Form to a variable of type Control without needing an explicit conversion, eg Form1 f = new Form1();...
36
3587
by: Chad Z. Hower aka Kudzu | last post by:
I have an implicit conversion set up in an assembly from a Stream to something else. In C#, it works. In VB it does not. Does VB support implicit conversions? And if so any idea why it would work...
4
2512
by: Edmund Dengler | last post by:
Howdy all! Just checking on whether this is the expected behaviour. I am transferring data from multiple databases to single one, and I want to ensure that I only have unique rows for some...
10
1693
by: Ralf | last post by:
Regarding numerical types, in my view, casts fall in one of two categories: 1. Casts that change the value of an object 2. Casts that are actually redundant, but get rid of compiler/lint warnings...
17
2465
by: arindam.mukerjee | last post by:
I was running code like: #include <stdio.h> int main() { printf("%f\n", 9/5); return 0; }
81
3223
by: jacob navia | last post by:
Hi I am still writing my tutorial book about C. Here is the section about casts. I would be interested in your opinions about this. Some people have definite views about this subject ("never...
12
3257
by: lithiumcat | last post by:
Hi, I bothered you a while back about storing integer values in void*. Now in a completely unrelated context, I'm trying to store pointer values in an integer type. So the basic question is,...
0
7125
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
7203
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...
1
6885
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
7379
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
5462
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
3093
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
3081
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
656
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
290
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

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.