www.digitalmars.com         C & C++   DMDScript  

digitalmars.D - Integer overflows

reply bearophile <bearophileHUGS lycos.com> writes:
A short article from July 01, 2008, shows that some people are re-inventing the
integer overflows compiler check that Pascal/Delphi programmers have enjoyed
for lot of years:

http://www.ddj.com/hpc-high-performance-computing/208801981

This time I am happy that history is repeating itself.

Bye,
bearophile
Jul 06 2008
parent reply superdan <super dan.org> writes:
bearophile Wrote:

 A short article from July 01, 2008, shows that some people are re-inventing
the integer overflows compiler check that Pascal/Delphi programmers have
enjoyed for lot of years:
 
 http://www.ddj.com/hpc-high-performance-computing/208801981
 
 This time I am happy that history is repeating itself.
me 2 but the article is just a rant. we should demand this from languages and computers. well yeah i demand a cow with diet coke too. i was always unclear on somethin'. should the check be in the operation or the type of the operand? i mean maybe i have some data and only sometimes i want to make sure there's no overflow. so i'm sayin' int a, b, c; a = b _+_ c; or something. that _+_ is checked and shit. or should i be like Safe!(int) a, b, c; a = b + c; arguments could go both ways i guess. the advantage of the albeit uglier first solution is that it is more likely to be used. somehow safe types keep on comin' in languages but people don't use'em if thery're not the default. positive bias i suppose. (ppl underestimate the likelihood of bad shit happening to'em and overestimate their capacity to avoid bad shit when it is imminent.)
Jul 06 2008
next sibling parent reply "Nick Sabalausky" <a a.a> writes:
"superdan" <super dan.org> wrote in message 
news:g4r88k$qjj$1 digitalmars.com...
 bearophile Wrote:

 A short article from July 01, 2008, shows that some people are 
 re-inventing the integer overflows compiler check that Pascal/Delphi 
 programmers have enjoyed for lot of years:

 http://www.ddj.com/hpc-high-performance-computing/208801981

 This time I am happy that history is repeating itself.
me 2 but the article is just a rant. we should demand this from languages and computers. well yeah i demand a cow with diet coke too. i was always unclear on somethin'. should the check be in the operation or the type of the operand? i mean maybe i have some data and only sometimes i want to make sure there's no overflow. so i'm sayin' int a, b, c; a = b _+_ c; or something. that _+_ is checked and shit. or should i be like Safe!(int) a, b, c; a = b + c; arguments could go both ways i guess. the advantage of the albeit uglier first solution is that it is more likely to be used. somehow safe types keep on comin' in languages but people don't use'em if thery're not the default. positive bias i suppose. (ppl underestimate the likelihood of bad shit happening to'em and overestimate their capacity to avoid bad shit when it is imminent.)
"checked" and "unchecked" keywords. (Heh heh, yes, here I go praising just look up the whole "no IArithmetic" bizzareness. Anyway...)) The way it works is this: In the compiler settings, you can choose a default, either artithmetic is checked for overflows by default or not checked by default. Then, in the code, you can override the compiler setting by doing something like this: checked { // Code here } unchecked { // Code here } a = checked(b + c); a = unchecked(b + c);
Jul 06 2008
parent reply superdan <super dan.org> writes:
Nick Sabalausky Wrote:

 "superdan" <super dan.org> wrote in message 
 news:g4r88k$qjj$1 digitalmars.com...
 bearophile Wrote:

 A short article from July 01, 2008, shows that some people are 
 re-inventing the integer overflows compiler check that Pascal/Delphi 
 programmers have enjoyed for lot of years:

 http://www.ddj.com/hpc-high-performance-computing/208801981

 This time I am happy that history is repeating itself.
me 2 but the article is just a rant. we should demand this from languages and computers. well yeah i demand a cow with diet coke too. i was always unclear on somethin'. should the check be in the operation or the type of the operand? i mean maybe i have some data and only sometimes i want to make sure there's no overflow. so i'm sayin' int a, b, c; a = b _+_ c; or something. that _+_ is checked and shit. or should i be like Safe!(int) a, b, c; a = b + c; arguments could go both ways i guess. the advantage of the albeit uglier first solution is that it is more likely to be used. somehow safe types keep on comin' in languages but people don't use'em if thery're not the default. positive bias i suppose. (ppl underestimate the likelihood of bad shit happening to'em and overestimate their capacity to avoid bad shit when it is imminent.)
"checked" and "unchecked" keywords. (Heh heh, yes, here I go praising just look up the whole "no IArithmetic" bizzareness. Anyway...)) The way it works is this: In the compiler settings, you can choose a default, either artithmetic is checked for overflows by default or not checked by default. Then, in the code, you can override the compiler setting by doing something like this: checked { // Code here } unchecked { // Code here } a = checked(b + c); a = unchecked(b + c);
does that checked stuff see through function calls?
Jul 06 2008
parent "Nick Sabalausky" <a a.a> writes:
"superdan" <super dan.org> wrote in message 
news:g4rg1u$1en7$1 digitalmars.com...
 Nick Sabalausky Wrote:

 "superdan" <super dan.org> wrote in message
 news:g4r88k$qjj$1 digitalmars.com...
 bearophile Wrote:

 A short article from July 01, 2008, shows that some people are
 re-inventing the integer overflows compiler check that Pascal/Delphi
 programmers have enjoyed for lot of years:

 http://www.ddj.com/hpc-high-performance-computing/208801981

 This time I am happy that history is repeating itself.
me 2 but the article is just a rant. we should demand this from languages and computers. well yeah i demand a cow with diet coke too. i was always unclear on somethin'. should the check be in the operation or the type of the operand? i mean maybe i have some data and only sometimes i want to make sure there's no overflow. so i'm sayin' int a, b, c; a = b _+_ c; or something. that _+_ is checked and shit. or should i be like Safe!(int) a, b, c; a = b + c; arguments could go both ways i guess. the advantage of the albeit uglier first solution is that it is more likely to be used. somehow safe types keep on comin' in languages but people don't use'em if thery're not the default. positive bias i suppose. (ppl underestimate the likelihood of bad shit happening to'em and overestimate their capacity to avoid bad shit when it is imminent.)
named:) "checked" and "unchecked" keywords. (Heh heh, yes, here I go praising gimped - just look up the whole "no IArithmetic" bizzareness. Anyway...)) The way it works is this: In the compiler settings, you can choose a default, either artithmetic is checked for overflows by default or not checked by default. Then, in the code, you can override the compiler setting by doing something like this: checked { // Code here } unchecked { // Code here } a = checked(b + c); a = unchecked(b + c);
does that checked stuff see through function calls?
I would assume so, but I'd really have to look it up or do a test to be sure.
Jul 06 2008
prev sibling parent JAnderson <ask me.com> writes:
superdan wrote:
 bearophile Wrote:
 
 A short article from July 01, 2008, shows that some people are re-inventing
the integer overflows compiler check that Pascal/Delphi programmers have
enjoyed for lot of years:

 http://www.ddj.com/hpc-high-performance-computing/208801981

 This time I am happy that history is repeating itself.
me 2 but the article is just a rant. we should demand this from languages and computers. well yeah i demand a cow with diet coke too. i was always unclear on somethin'. should the check be in the operation or the type of the operand? i mean maybe i have some data and only sometimes i want to make sure there's no overflow. so i'm sayin' int a, b, c; a = b _+_ c; or something. that _+_ is checked and shit. or should i be like Safe!(int) a, b, c; a = b + c;
This reminds me of ADA. It had this range and subrange types which you could specify any range for a number and the runtime would validate it for you. They could also be passed in as ranges for arrays which was kinda neat.
 
 arguments could go both ways i guess. the advantage of the albeit uglier first
solution is that it is more likely to be used. somehow safe types keep on
comin' in languages but people don't use'em if thery're not the default.
positive bias i suppose. (ppl underestimate the likelihood of bad shit
happening to'em and overestimate their capacity to avoid bad shit when it is
imminent.)
Jul 07 2008