www.digitalmars.com         C & C++   DMDScript  

digitalmars.D - Rethinking implicit casts

reply Manfred Nowak <svv1999 hotmail.com> writes:
http://msdn.microsoft.com/library/default.asp?url=/library/en-
us/cpgenref/html/cpconcasts.asp clearly states, that implicit casting 
should not be made when one of the following holds
1. information is lost
2. a semantically different value is generated
3. the target belongs to another domain

Although it is not precisely defined what a "domain" is or 
"semantically difference" I tend to follow this suggestions.

The result would be, that unsigned values like `uint' are no more 
implicitely castable into signed values linke `int' and vice versa, 
that `float' can only be casted implicitely to `double' or `real' and 
`double' only to `real'.

The link above also gives me the insight that my stunned glaring at 
the implicit casts from `int' to `char' and vice versa had a reason, 
when I first noticed them in C.

How much congeniality to C is wishable for D despite of the stated 
dangerousness.

-manfred   
Feb 25 2005
parent reply Georg Wrede <georg.wrede nospam.org> writes:
Manfred Nowak wrote:
 http://msdn.microsoft.com/library/default.asp?url=/library/en-
 us/cpgenref/html/cpconcasts.asp clearly states, that implicit casting 
 should not be made when one of the following holds
 1. information is lost
 2. a semantically different value is generated
 3. the target belongs to another domain
 
 Although it is not precisely defined what a "domain" is or 
 "semantically difference" I tend to follow this suggestions.
 
 The result would be, that unsigned values like `uint' are no more 
 implicitely castable into signed values linke `int' and vice versa, 
 that `float' can only be casted implicitely to `double' or `real' and 
 `double' only to `real'.

This, and a few previous threads got me thinking. Casting, implicit casting, and overloading, I think, should always be considered together. In other words, in the future we shouldn't have threads about any one topic of these as such, but instead always try to look at all three in the threads. It's a pity that there's no word for it. (I.e. no word that means casting+implicitCasting+overloading.) All I can think of is "the type issue". :-( ps. the unfinished subject about function selection by return type should also be included in this.
Feb 27 2005
parent "Matthew" <admin stlsoft.dot.dot.dot.dot.org> writes:
"Georg Wrede" <georg.wrede nospam.org> wrote in message 
news:42223786.4040407 nospam.org...
 Manfred Nowak wrote:
 http://msdn.microsoft.com/library/default.asp?url=/library/en-
 us/cpgenref/html/cpconcasts.asp clearly states, that implicit casting 
 should not be made when one of the following holds
 1. information is lost
 2. a semantically different value is generated
 3. the target belongs to another domain

 Although it is not precisely defined what a "domain" is or 
 "semantically difference" I tend to follow this suggestions.

 The result would be, that unsigned values like `uint' are no more 
 implicitely castable into signed values linke `int' and vice versa, 
 that `float' can only be casted implicitely to `double' or `real' and 
 `double' only to `real'.

This, and a few previous threads got me thinking. Casting, implicit casting, and overloading, I think, should always be considered together. In other words, in the future we shouldn't have threads about any one topic of these as such, but instead always try to look at all three in the threads. It's a pity that there's no word for it. (I.e. no word that means casting+implicitCasting+overloading.)

Conversion
Feb 27 2005