Path: utzoo!utgpu!news-server.csri.toronto.edu!cs.utexas.edu!usc!ucsd!ucbvax!hplabs!hpcc01!hp-ptp!hp-ses!wunder From: wunder@hp-ses.SDE.HP.COM (Walter Underwood) Newsgroups: comp.sys.hp Subject: Re: C Compiler Optimizer Message-ID: <920067@hp-ses.SDE.HP.COM> Date: 29 Aug 90 18:39:30 GMT References: <59169@bbn.BBN.COM> Organization: HP SW Engineering Systems - Sunnyvale, CA Lines: 38 example.c ------ main() { printf("hello, world\n"); } Exiting with an unpredictable number is proper behavior for this program. It is not a defect. Notice: $ lint /tmp/example.c example.c ============== (6) warning: main() returns random value to invocation environment ... Which is exactly what your code does when optimized. The repeatable behavior when not optimized is due to luck, not C. Here is a fixed version of "example.c". int main() { printf("hello, world\n"); return 0; } Now, the main() routine returns a type which matches its declared return type. This is correct C. When program behavior changes under optimization, use lint to find out whether the code depends on things that C doesn't guarantee. You can also use C++, which has much more strict checking and just won't compile code with type mismatches. wunder