digitalmars.D - Rethinking implicit casts
- Manfred Nowak (18/18) Feb 25 2005 http://msdn.microsoft.com/library/default.asp?url=/library/en-
- Georg Wrede (12/26) Feb 27 2005 This, and a few previous threads got me thinking.
- Matthew (3/26) Feb 27 2005 Conversion
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
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
"Georg Wrede" <georg.wrede nospam.org> wrote in message news:42223786.4040407 nospam.org...Manfred Nowak wrote:Conversionhttp://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.)
Feb 27 2005