June 22, 2013 Re: Undefined behaviors & Clang 3.3 | ||||
---|---|---|---|---|
| ||||
Posted in reply to Artur Skawina | On Friday, 21 June 2013 at 14:48:46 UTC, Artur Skawina wrote:
> On 06/21/13 15:48, eles wrote:
>> On Friday, 21 June 2013 at 10:42:32 UTC, bearophile wrote:
> Actually, it's the other way around - mandating wrapping is what makes it
> possible for code to detect the overflow. Having overflow be
Very much aware of that. However, going from undefined to (badly) defined is not the best choice, as long as better is available.
|
June 22, 2013 Re: Undefined behaviors & Clang 3.3 | ||||
---|---|---|---|---|
| ||||
Posted in reply to qznc | On Friday, 21 June 2013 at 15:51:55 UTC, qznc wrote: > On Friday, 21 June 2013 at 13:48:19 UTC, eles wrote: >> On Friday, 21 June 2013 at 10:42:32 UTC, bearophile wrote: > > The D definition mirrors what modern PC architectures do and hence can be compiled efficiently there. C avoids coupling with any architecture hence "undefined". First, it is not just about UNDEFINED behaviour, but also about DESIRED behaviur. C's arrays seen as pointers were efficient (and mirroring the architecture who kne nothing about arrays, just about addresses, that is pointers), still D abandoned them for a good reason. Efficiency vs better is a sensible trade-off. Secondly, is just enabling that overflow behavior if chasing a bug, explicitely, with a compiler flag. Use it only if you care. Although the best solution, in my eyes, is to have both wrapping and overfloing signed and unsigned integer types. Chose what you want. > What architectures do not wrap around? They wrap, but they carry. BTW, floats do not wrap, why integers should behave otherwise? |
June 22, 2013 Re: Undefined behaviors & Clang 3.3 | ||||
---|---|---|---|---|
| ||||
Posted in reply to eles | On Sat, 22 Jun 2013 02:14:18 +0200, eles <eles@eles.com> wrote: > BTW, floats do not wrap, why integers should behave otherwise? Because that's how the hardware works. IEEE-754 floats have special values that do not behave like other numbers: infinity and nan. The ints the hardware supports have no such thing. Of course, one could write a complex wrapper around the int to get infinity in there, and even nan if one really wanted, but that'd be a lot less efficient, and contrary to how people expect things to work. -- Simen |
June 24, 2013 Re: Undefined behaviors & Clang 3.3 | ||||
---|---|---|---|---|
| ||||
Posted in reply to Simen Kjaeraas | On Saturday, 22 June 2013 at 07:59:05 UTC, Simen Kjaeraas wrote:
> On Sat, 22 Jun 2013 02:14:18 +0200, eles <eles@eles.com> wrote:
> Of course, one could write a complex wrapper around the int to get infinity
> in there, and even nan if one really wanted, but that'd be a lot less
> efficient, and contrary to how people expect things to work.
They would never carry when wrapping up if that would have been the case.
|
June 25, 2013 Re: Undefined behaviors & Clang 3.3 | ||||
---|---|---|---|---|
| ||||
Posted in reply to qznc | On Friday, 21 June 2013 at 15:51:55 UTC, qznc wrote:
> What architectures do not wrap around?
The MIPS has instructions which trap on integer overflow (it has other which wrap too).
Unfortunately, this is the only CPU I know where you can have a sane integer semantic "for free".
renoX
|
Copyright © 1999-2021 by the D Language Foundation