Summation on HP 42S
|
09-29-2018, 04:06 PM
(This post was last modified: 09-29-2018 04:07 PM by ijabbott.)
Post: #45
|
|||
|
|||
RE: Summation on HP 42S
(09-29-2018 01:50 PM)Thomas Okken Wrote: I am honestly curious to see examples of incorrect code that somehow manages to work as intended when not optimized, and fails when optimized. Maybe it exists, but it's not something I've come across. Not my example, but consider this C program: Code: #include <stdio.h> Function f() takes the int value 1 and repeatedly doubles it until it overflows and goes negative. (Perhaps the programmer is intending to discover the number of non-sign bits in an int or something.) Compile it in GCC with no optimisation and run it: Code: $ gcc foo.c On my system, it prints 31 as shown. Now recompile it with optimisation level 2 and run it again: Code: $ gcc -O2 foo.c On my system, it just sits there in an infinite loop until I kill it. If you think that is a bug in the optimiser, well, it isn't. — Ian Abbott |
|||
« Next Oldest | Next Newest »
|
User(s) browsing this thread: 8 Guest(s)