Jump to page: 1 2 3
Thread overview
automatic int to short conversion - the HELL?
Sep 18, 2008
downs
Does it have anything to do with short x; typeof(x+1) == int?
Sep 18, 2008
downs
Sep 18, 2008
downs
Sep 18, 2008
Chris R. Miller
Sep 18, 2008
downs
Sep 18, 2008
Chris R. Miller
Sep 18, 2008
Ary Borenszweig
Sep 18, 2008
Chris R. Miller
Sep 18, 2008
Bill Baxter
Sep 19, 2008
bearophile
Sep 19, 2008
Ary Borenszweig
Sep 19, 2008
Ary Borenszweig
Sep 19, 2008
Ary Borenszweig
Sep 19, 2008
Don
Sep 19, 2008
Sean Kelly
Sep 19, 2008
bearophile
Sep 20, 2008
Sean Kelly
Sep 20, 2008
bearophile
Sep 20, 2008
bearophile
Sep 18, 2008
Janderson
September 18, 2008
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
n/t
September 18, 2008
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
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
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
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
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
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
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
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".
« First   ‹ Prev
1 2 3