r/programming • • May 30 '17

Compiler Optimizations are Awesome

https://blog.regehr.org/archives/1515
146 Upvotes

97 comments sorted by

View all comments

Show parent comments

1

u/industry7 May 31 '17

How would you define the outcome of signed integer overflow? How would that definition make code that (inadvertently) induces signed integer overflow better?

Make it signal. That makes code better b/c you can now handle the error case consistently across platforms.

Alternatively, a sufficiently advanced type system could enforce compile time restraints in such a way that unmitigated potential overflows won't compile.

There's a lot of different ways that a language could handle this situation.

2

u/mcmcc May 31 '17

Make it signal.

Hardware vendors' collective heads would explode.

a sufficiently advanced type system

... would be unwieldy. Languages have tried this and you find yourself working around the type system. Sometimes (often) numbers are just numbers.

1

u/industry7 Jun 01 '17

... would be unwieldy. Languages have tried this and you find yourself working around the type system.

Maybe you find yourself working around advanced type systems, but I generally find the more advanced the type system the more my productivity is enhanced.

Sometimes (often) numbers are just numbers.

Until they under/over-flow and/or the compiler decides to optimize away important part of your program, and then it's a huge problem in addition to being "just numbers".

0

u/mcmcc Jun 01 '17

I'll ask again, what general problem does defined signed overflow actually solve?

Read the other branches in this thread for context.

1

u/industry7 Jun 01 '17

How would that definition make code that (inadvertently) induces signed integer overflow better?

I'll ask again, what general problem does defined signed overflow actually solve?

The general problem is undefined behavior... Defining the behavior fixes the problem... by defining the behavior.

What's your question again?

→ More replies (0)