home *** CD-ROM | disk | FTP | other *** search
- Path: sparky!uunet!pmafire!news.dell.com!swrinde!sdd.hp.com!scd.hp.com!cupnews0.cup.hp.com!hppad.waterloo.hp.com!hppad!hpfcso!mjs
- From: mjs@hpfcso.FC.HP.COM (Marc Sabatella)
- Newsgroups: comp.sys.hp
- Subject: Re: that HPUX cc compiler
- Message-ID: <7371293@hpfcso.FC.HP.COM>
- Date: 4 Sep 92 21:40:31 GMT
- References: <1992Aug31.104950.1108@bohra.cpg.oz.au>
- Organization: Hewlett-Packard, Fort Collins, CO, USA
- Lines: 29
-
- In comp.sys.hp, jaenicke@emserver.ee.tu-berlin.de (Lutz Jaenicke) writes:
-
- > while(fread(entry, sizeof entry, 1, u))
- > bogus = entry.ut_time;
- > ...
- > You could have saved much time, even though I cannot explain why the program
- > is running without -O. It must not run!
-
- Indeed, there are many examples of programs that fail when optimized due to
- problems in the code. "lint" (or "lintfor" for you Fortran types) can be a big
- help here - it will show mismatched parameters, missing parameters,
- uninitialized local variables, etc. ANSI C catches some of these as well, but
- can't do the interfile checking that "lint" does, and only checks for
- uninitialized variables when compiling optimized.
-
- I suspect the reason the example code worked at all unoptimized is that, when
- you accidentally passed the structure by value it was placed on the stack (as
- are all structures), but fread() itself expected its first argument to be a
- pointer, so it took the value from a register (as are all scalar first
- arguments). Unoptimized, that register happened to have the value of the
- address of the structure you intended to pass by reference, so fread() put the
- data it read into the right place. Optimized, that register contained some
- other value, so fread() tried to put the data somewhere else.
-
- --------------
- Marc Sabatella (marc@hpmonk.fc.hp.com)
- Disclaimers:
- 2 + 2 = 3, for suitably small values of 2
- Bill (H.) and Dave (P.) may not always agree with me
-