This testcase: int f () { double d = 128.; return (signed char) d; }
int main () { return f () != -128; } Succeeds at -O0 and fails at -O1. While the C standard says that the result of the conversion is unspecified, it is a quality of implementation issue to give, where reasonably possible, the same results when optimizing as when not optimizing. Doing otherwise makes debugging unnecessarily difficult. -- Summary: double -> char conversion varies with optimization level Product: gcc Version: 4.2.0 Status: UNCONFIRMED Severity: normal Priority: P3 Component: tree-optimization AssignedTo: unassigned at gcc dot gnu dot org ReportedBy: amylaar at gcc dot gnu dot org http://gcc.gnu.org/bugzilla/show_bug.cgi?id=27394