A strange div bug on Linux x86_64, (both dmd & ldc2): long -5000 / size_t 2 = 9223372036854773308
newshound2 at digitalmars.com
Fri Aug 14 09:12:50 UTC 2020
On 8/13/2020 10:47 PM, Simen Kjærås wrote:
> This does not in any way address the problem here, namely that the intuitive way
> to do things causes issues in possibly-very-rare situations.
On a more personal note, I came to C from Pascal. Pascal required explicit casts
everywhere one did mixed integer arithmetic. I grew to dislike it, it was ugly
and just plain annoying.
Then a friend loaned me K+R, and the way its expressions worked was simple and
effective, and looked a lot nicer on the page. I never had any trouble with it.
(To be fair, at the time I had done a lot of assembler programming and was very
well aware of 2's complement arithmetic. I also had done a lot of PDP-11
assembler and recognized the integral promotion semantics from that.) I never
wrote another line of Pascal.
The only thing I did like about Pascal was its way of nested functions, which
were marvelous and hence D's marvelous nested functions :-)
As for intuitive, what that really means is what you're used to. 2's complement
arithmetic is intuitive for systems programmers and assembler programmers,
people coming from school arithmetic are going to find it unintuitive. There
isn't a way to please everyone, we have to make a choice.
P.S. I should add to my previous list that people doing systems programming need
to come to terms with size_t, ptrdiff_t, and their model dependent behavior. At
least D doesn't do random sizes for int, and the random signed-ness of char. C
people get regularly punished for assuming char is signed or unsigned. Maybe I
should expand this into an article.
More information about the Digitalmars-d