Thread overview | |||||||||
---|---|---|---|---|---|---|---|---|---|
|
February 07, 2006 Warnings about potential loss of data | ||||
---|---|---|---|---|
| ||||
Assuming that the idea behind the "-w" switch is to help coders locate the assumptions that the compiler is making on our behalf, I think that it would be useful to add an "optional error" when the compiler detects a potential loss of data.
Example 1:
import std.stdio;
void main()
{
uint a;
int b;
b = -3;
a = b; // A warning here would be appreciated.
writefln("a = ", a, ", b = ", b);
// result: a = 4294967293, b = -3
}
Example 2:
void Foo()
{
int a;
long b;
b = SomeFunction();
a = b; // A warning here would be appreciated.
}
and there are many other examples too.
--
Derek
(skype: derek.j.parnell)
Melbourne, Australia
"Down with mediocracy!"
7/02/2006 11:16:27 AM
|
February 07, 2006 Re: Warnings about potential loss of data | ||||
---|---|---|---|---|
| ||||
Posted in reply to Derek Parnell | Derek Parnell wrote:
> Assuming that the idea behind the "-w" switch is to help coders locate the
> assumptions that the compiler is making on our behalf, I think that it
> would be useful to add an "optional error" when the compiler detects a
> potential loss of data.
Agreed. I'd like the compiler to warn me about narrowing conversions that don't use an explicit cast.
Sean
|
February 07, 2006 Re: Warnings about potential loss of data | ||||
---|---|---|---|---|
| ||||
Posted in reply to Sean Kelly | "Sean Kelly" <sean@f4.ca> wrote in message news:ds8pmm$ups$1@digitaldaemon.com... > Derek Parnell wrote: > > Assuming that the idea behind the "-w" switch is to help coders locate the > > assumptions that the compiler is making on our behalf, I think that it would be useful to add an "optional error" when the compiler detects a potential loss of data. > > Agreed. I'd like the compiler to warn me about narrowing conversions that don't use an explicit cast. Wistfully ROFL! |
February 07, 2006 Re: Warnings about potential loss of data | ||||
---|---|---|---|---|
| ||||
Posted in reply to Derek Parnell | Derek Parnell wrote: > Assuming that the idea behind the "-w" switch is to help coders locate the > assumptions that the compiler is making on our behalf, I think that it > would be useful to add an "optional error" when the compiler detects a > potential loss of data. What is an "optional error"? Either a piece of code is legal, or it isn't, surely? <snip> > Example 2: > void Foo() > { > int a; > long b; > b = SomeFunction(); > a = b; // A warning here would be appreciated. > } <snip> I'd like this to be an error. Stewart. -- -----BEGIN GEEK CODE BLOCK----- Version: 3.1 GCS/M d- s:- C++@ a->--- UB@ P+ L E@ W++@ N+++ o K-@ w++@ O? M V? PS- PE- Y? PGP- t- 5? X? R b DI? D G e++>++++ h-- r-- !y ------END GEEK CODE BLOCK------ My e-mail is valid but not my primary mailbox. Please keep replies on the 'group where everyone may benefit. |
February 07, 2006 Re: Warnings about potential loss of data | ||||
---|---|---|---|---|
| ||||
Posted in reply to Stewart Gordon | In article <dsa2nv$1v8q$1@digitaldaemon.com>, Stewart Gordon says... > >What is an "optional error"? Either a piece of code is legal, or it isn't, surely? > ><snip> >> Example 2: >> void Foo() >> { >> int a; >> long b; >> >> b = SomeFunction(); >> a = b; // A warning here would be appreciated. >> >> } ><snip> > >I'd like this to be an error. > >Stewart. > Yep this is error - some rocket can fall down because of this! -- UB |
February 07, 2006 Re: Warnings about potential loss of data | ||||
---|---|---|---|---|
| ||||
Posted in reply to Stewart Gordon | On Tue, 07 Feb 2006 23:10:39 +1100, Stewart Gordon <smjg_1998@yahoo.com> wrote: > Derek Parnell wrote: >> Assuming that the idea behind the "-w" switch is to help coders locate the >> assumptions that the compiler is making on our behalf, I think that it >> would be useful to add an "optional error" when the compiler detects a >> potential loss of data. > > What is an "optional error"? Either a piece of code is legal, or it isn't, surely? It was from something that Walter said about "-w" warnings ... 'Think of them as "optional errors" instead of warnings <g>.' - Walter -- Derek Parnell Melbourne, Australia |
February 07, 2006 Re: Warnings about potential loss of data | ||||
---|---|---|---|---|
| ||||
Posted in reply to Derek Parnell | Derek Parnell wrote:
> On Tue, 07 Feb 2006 23:10:39 +1100, Stewart Gordon <smjg_1998@yahoo.com> wrote:
>
>> Derek Parnell wrote:
>>
>>> Assuming that the idea behind the "-w" switch is to help coders locate the
>>> assumptions that the compiler is making on our behalf, I think that it
>>> would be useful to add an "optional error" when the compiler detects a
>>> potential loss of data.
>>
>>
>> What is an "optional error"? Either a piece of code is legal, or it isn't, surely?
>
>
> It was from something that Walter said about "-w" warnings ...
>
> 'Think of them as "optional errors" instead of warnings <g>.' - Walter
>
"pedantic errors" might be a better term.
I think that what you're doing is telling the compiler something about your coding style (and perhaps, what kinds of bugs you create).
|
Copyright © 1999-2021 by the D Language Foundation