From mboxrd@z Thu Jan 1 00:00:00 1970 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on polar.synack.me X-Spam-Level: X-Spam-Status: No, score=-1.3 required=5.0 tests=BAYES_00,INVALID_MSGID autolearn=no autolearn_force=no version=3.4.4 X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 103376,d1df6bc3799debed X-Google-Attributes: gid103376,public From: Simon Wright Subject: Re: Not intended for use in medical, Date: 1997/05/03 Message-ID: #1/1 X-Deja-AN: 239138625 X-NNTP-Posting-Host: pogner.demon.co.uk References: <3.0.32.19970423164855.00746db8@mail.4dcomm.com> <3364C8EC.4879@DIE_SPAMMER.dasd.honeywell.com> <5k5ifi$8db@bcrkh13.bnr.ca> Organization: At Home Newsgroups: comp.lang.ada Date: 1997-05-03T00:00:00+00:00 List-Id: kaz@vision.crest.nt.com (Kaz Kylheku) writes: > int foo(int x, int y) > > { > return ((x < y) && x++) && ((x < y) && x++); > } [...] > /* > * GCC seems to illegaly optimize foo() by factoring the (x < y) > * as a common subexpression ignoring the x++ side effect, e.g: > * > * return ((x < y) && x++) && x++; > * > * A more complex version of this expression has caused a serious > * failure in some of my code. > */ [...] > I readily discovered this problem when my program was behaving oddly, and > a thorough code inspection failed to turn up any error in the source. Hmm. I believe that writing eg a[i] = ++i; invokes undefined behaviour (is the pre- or post- value of i used for the index operation?). While inspecting your program, I would be fairly sure of the meaning you intended but quite unsure without checking the standard as to whether it had entered the realm of the undefined. And I see that your original code was _more_ complex! Crikey! I would also wonder why the second ++ was there anyway, it has no effect (unless of course x was a reference, but we're talking C here, and then the effect of the code would be amazingly hard to understand) -- Simon Wright Work Email: simon.j.wright@gecm.com GEC-Marconi Radar & Defence Systems Voice: +44(0)1705-701778 Command & Information Systems Divsion FAX: +44(0)1705-701800