Thread overview | |||||||||||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
September 18, 2008 automatic int to short conversion - the HELL? | ||||
---|---|---|---|---|
| ||||
void main() { int i; short x; x = i; } Excuse me, but - how exactly is it that this is in any way, shape or form valid code? How can I trust a language that allows those kind of shenanigans? |
September 18, 2008 Does it have anything to do with short x; typeof(x+1) == int? | ||||
---|---|---|---|---|
| ||||
Posted in reply to downs | n/t |
September 18, 2008 Re: automatic int to short conversion - the HELL? | ||||
---|---|---|---|---|
| ||||
Posted in reply to downs | On Wed, Sep 17, 2008 at 10:26 PM, downs <default_357-line@yahoo.de> wrote:
> void main() { int i; short x; x = i; }
>
> Excuse me, but - how exactly is it that this is in any way, shape or form valid code?
>
> How can I trust a language that allows those kind of shenanigans?
>
lern2warningsflag.
|
September 18, 2008 Re: Does it have anything to do with short x; typeof(x+1) == int? | ||||
---|---|---|---|---|
| ||||
Posted in reply to downs | On Wed, Sep 17, 2008 at 10:32 PM, downs <default_357-line@yahoo.de> wrote:
> n/t
>
I'm not sure what this has to do with you not specifying -w.
|
September 18, 2008 Re: automatic int to short conversion - the HELL? | ||||
---|---|---|---|---|
| ||||
Posted in reply to Jarrett Billingsley | Jarrett Billingsley wrote:
> On Wed, Sep 17, 2008 at 10:26 PM, downs <default_357-line@yahoo.de> wrote:
>> void main() { int i; short x; x = i; }
>>
>> Excuse me, but - how exactly is it that this is in any way, shape or form valid code?
>>
>> How can I trust a language that allows those kind of shenanigans?
>>
>
> lern2warningsflag.
"Warning. Your code is broken."
I still claim it should actually be an error, although the only practical and correct solution might be full ranged type support.
|
September 18, 2008 Re: automatic int to short conversion - the HELL? | ||||
---|---|---|---|---|
| ||||
Posted in reply to downs | downs wrote:
> Jarrett Billingsley wrote:
>> On Wed, Sep 17, 2008 at 10:26 PM, downs <default_357-line@yahoo.de> wrote:
>>> void main() { int i; short x; x = i; }
>>>
>>> Excuse me, but - how exactly is it that this is in any way, shape or form valid code?
>>>
>>> How can I trust a language that allows those kind of shenanigans?
>>>
>> lern2warningsflag.
>
> "Warning. Your code is broken."
>
> I still claim it should actually be an error, although the only practical and correct solution might be full ranged type support.
I don't get it. Why can that not be simple implicit type casting?
|
September 18, 2008 Re: automatic int to short conversion - the HELL? | ||||
---|---|---|---|---|
| ||||
Posted in reply to Chris R. Miller | Chris R. Miller wrote:
> downs wrote:
>> Jarrett Billingsley wrote:
>>> On Wed, Sep 17, 2008 at 10:26 PM, downs <default_357-line@yahoo.de> wrote:
>>>> void main() { int i; short x; x = i; }
>>>>
>>>> Excuse me, but - how exactly is it that this is in any way, shape or form valid code?
>>>>
>>>> How can I trust a language that allows those kind of shenanigans?
>>>>
>>> lern2warningsflag.
>>
>> "Warning. Your code is broken."
>>
>> I still claim it should actually be an error, although the only practical and correct solution might be full ranged type support.
>
> I don't get it. Why can that not be simple implicit type casting?
Because short is not a superset of int.
|
September 18, 2008 Re: automatic int to short conversion - the HELL? | ||||
---|---|---|---|---|
| ||||
Posted in reply to downs | downs wrote:
> void main() { int i; short x; x = i; }
>
> Excuse me, but - how exactly is it that this is in any way, shape or form valid code?
>
> How can I trust a language that allows those kind of shenanigans?
I totally agree. This should be an error. You should be required to explicitly cast.
-Joel
|
September 18, 2008 Re: automatic int to short conversion - the HELL? | ||||
---|---|---|---|---|
| ||||
Posted in reply to downs | downs wrote:
> Chris R. Miller wrote:
>> downs wrote:
>>> Jarrett Billingsley wrote:
>>>> On Wed, Sep 17, 2008 at 10:26 PM, downs <default_357-line@yahoo.de>
>>>> wrote:
>>>>> void main() { int i; short x; x = i; }
>>>>>
>>>>> Excuse me, but - how exactly is it that this is in any way, shape or
>>>>> form valid code?
>>>>>
>>>>> How can I trust a language that allows those kind of shenanigans?
>>>>>
>>>> lern2warningsflag.
>>> "Warning. Your code is broken."
>>>
>>> I still claim it should actually be an error, although the only
>>> practical and correct solution might be full ranged type support.
>> I don't get it. Why can that not be simple implicit type casting?
>
> Because short is not a superset of int.
Well.... then it's just a loss of precision warning like on every other language (Java and C++ off the top of my head).
-w and be on thy way, unless I'm missing something else.
|
September 18, 2008 Re: automatic int to short conversion - the HELL? | ||||
---|---|---|---|---|
| ||||
Posted in reply to Chris R. Miller | Chris R. Miller wrote: > downs wrote: >> Chris R. Miller wrote: >>> downs wrote: >>>> Jarrett Billingsley wrote: >>>>> On Wed, Sep 17, 2008 at 10:26 PM, downs <default_357-line@yahoo.de> >>>>> wrote: >>>>>> void main() { int i; short x; x = i; } >>>>>> >>>>>> Excuse me, but - how exactly is it that this is in any way, shape or >>>>>> form valid code? >>>>>> >>>>>> How can I trust a language that allows those kind of shenanigans? >>>>>> >>>>> lern2warningsflag. >>>> "Warning. Your code is broken." >>>> >>>> I still claim it should actually be an error, although the only >>>> practical and correct solution might be full ranged type support. >>> I don't get it. Why can that not be simple implicit type casting? >> >> Because short is not a superset of int. > > Well.... then it's just a loss of precision warning like on every other language (Java and C++ off the top of my head). > > -w and be on thy way, unless I'm missing something else. No, no. In Java it's an error, an explicit cast is required. http://www.programmersheaven.com/2/FAQ-JAVA-Type-Conversion-Casting Which is perfect. It expresses the intents of the programmer: long x = ...; int y = (int) x; // yes, I know I might loose information, but I'm sure // it won't happen However, if you see this code (in D): long x = ...; int y = x; you start wondering whether the original author simply forgot to add the cast or he knew what he was doing. How can you know? I like the compiler to force you to write an explicit cast. It is saying: "Hey, please tell me you know what you are doing here... because maybe you didn't notice you might loose information here". |
Copyright © 1999-2021 by the D Language Foundation