Article View: comp.unix.programmer
Article #3676Re: gcc -O2 bug
From: Orc
Date: Sat, 10 Aug 1996 00:00
Date: Sat, 10 Aug 1996 00:00
42 lines
2628 bytes
2628 bytes
In article <danpop.839541415@news.cern.ch>, Dan Pop <Dan.Pop@cern.ch> wrote:
>In <vkohklaizj.fsf@atari.connectinc.com> bji@connectinc.com (Bryan Ischo) writes:
>
>>In article <danpop.839504721@news.cern.ch> Dan.Pop@cern.ch (Dan Pop) writes:
>> In <4ubnat$75u@freeside.fc.net> mrbig@freeside.fc.net (Mike Big) writes:
>>
>> >int *flag_pt;
>> >
[snip]
>> > while(flag){ /* does NOT exit when using gcc -O2 */
>>
>>[more skippage]
>>
>> > counter++;
>> > /* uncomenting the printf below will fix things. weird heh */
>>
>>Just out of curiosity ... why can't the compiler be sure that 'flag' won't be
>>modified by printf?
>
>Because flag is accessible via the flag_pt pointer, which is a global
>variable, hence available to any function called by the program.
>
>>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?
>
>On the contrary, it is smart enough to know that flag CAN be modified by
>a function called within the loop.
... but not smart enough to know that flag can be manipulated by a
signal driven function while the loop is running. Isn't optimization
fun? My first reaction, if I was still writing compilers, to assigning
a variable's address to a global would be to treat the variable as a
volatile from there on in, but I'm sure I could independently come up
with pretty much the same reasons as the ANSI committee did for why
that's not necessarily a good thing.
____
david parsons \bi/ It's better to be a firewall hacker; the pay is better
\/ and you only have to deal with people trying to break
in.
Technical Details
Message-ID:
<4uhp4i$pmu@pell.pell.chi.il.us>Path:
arc1-ca.pugleaf.net!unknown!not-for-mailReferences:
<4ubnat$75u@freeside.fc.net> <danpop.839504721@news.cern.ch> <vkohklaizj.fsf@atari.connectinc.com> <danpop.839541415@news.cern.ch>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: orc@pell.chi.il.us (Orc) Subject: Re: gcc -O2 bug Date: 1996/08/10 Message-ID: <4uhp4i$pmu@pell.pell.chi.il.us> X-Deja-AN: 173329939 references: <4ubnat$75u@freeside.fc.net> <danpop.839504721@news.cern.ch> <vkohklaizj.fsf@atari.connectinc.com> <danpop.839541415@news.cern.ch> organization: By the Holy Claws of Klortho the Magnificent, this IS a fine morning! newsgroups: comp.unix.programmer,gnu.gcc.help,comp.os.linux.development.apps,comp.lang.c