Article View: comp.unix.programmer
Article #3663Re: gcc -O2 bug
From: Peter Seebach
Date: Thu, 08 Aug 1996 00:00
Date: Thu, 08 Aug 1996 00:00
40 lines
2412 bytes
2412 bytes
In article <vkohklaizj.fsf@atari.connectinc.com>,
Bryan Ischo <bji@connectinc.com> wrote:
>Just out of curiosity ... why can't the compiler be sure that 'flag' won't be
>modified by printf?
Because it could be modified by printf.
>After all, its type is declared as int, not int *, and
>the loop conditional is 'while(flag)' not 'while (*flag)'.
So? &flag generates a pointer to it, through which it could be modified, and
any call to any function could possibly refer to it. Trivally,
printf("%n", &flag);
would be stupid but would modify flag.
>What I'm getting
>at is, the only way flag could be modified is if the programmer is assuming
>that the size of an int is the same as the size of an int * and is passing in
>an int in place of an int *, presumably one which has been casted from an
>int * somewhere earlier.
This is simply untrue. The programmer could have put flag's address in a
global, and a function named printf might modify the contents.
At least, I think what you're saying is untrue; I can't honestly understand a
word of it.
>Shouldn't the compiler be smart enough to know that flag can't be modified
>even IF the printf is in the loop, given how smart it's been about everything
>else?
Some versions might be, but it's an unlikely assumption.
-s
--
Peter Seebach - seebs@solon.com - Copyright 1996 - http://www.solon.com/~seebs
Unix/C Wizard - send mail for help, or send money for consulting!
The *other* C FAQ, the hacker FAQ, et al. See web page above.
Unsolicited email (junk mail and ads) is unwelcome, and will be billed for.
Technical Details
Message-ID:
<4udd3i$90k@solutions.solon.com>Path:
arc1-ca.pugleaf.net!unknown!not-for-mailReferences:
<4ubnat$75u@freeside.fc.net> <danpop.839504721@news.cern.ch> <vkohklaizj.fsf@atari.connectinc.com>Show Full Headers
Complete Article Headers
X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 11318c,7d30cae02ba9b089 X-Google-Attributes: gid11318c,public X-Google-Thread: 10c696,7d30cae02ba9b089 X-Google-Attributes: gid10c696,public X-Google-Thread: fc89c,7d30cae02ba9b089 X-Google-Attributes: gidfc89c,public X-Google-Thread: 1014db,7d30cae02ba9b089 X-Google-Attributes: gid1014db,public From: seebs@solutions.solon.com (Peter Seebach) Subject: Re: gcc -O2 bug Date: 1996/08/08 Message-ID: <4udd3i$90k@solutions.solon.com> X-Deja-AN: 172981282 references: <4ubnat$75u@freeside.fc.net> <danpop.839504721@news.cern.ch> <vkohklaizj.fsf@atari.connectinc.com> organization: Usenet Fact Police (Undercover) reply-to: seebs@solon.com newsgroups: comp.unix.programmer,gnu.gcc.help,comp.os.linux.development.apps,comp.lang.c