🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: comp.unix.programmer
Article #3682

Re: gcc -O2 bug

#3682
From: Preston F. Crow
Date: Mon, 12 Aug 1996 00:00
46 lines
3037 bytes
Christopher R Volpe <volpe@ash.crd.ge.com> writes:
>Preston F. Crow wrote:
>> Christopher R Volpe <volpe@ash.crd.ge.com> writes:
>> 
>> >comp.std.c answer: The compiler is allowed to know the semantics of
>> >printf, and should know that the printf function will not modify
>> >flag_pt, despite the fact that other user-defined functions could.
>> 
>> No, the compiler can't assume anything about printf(), as the user

>Bzzzt. Thanks for playing.

>> could have stupidly defined his own function of the same name,
>             ^^^^^^^^
>And the reason this would be "stupid" is that it's not legal for him to
>do so, since the compiler is allowed to know what printf does.

>> overriding the expected behaviour of the version in libc.
>> 
>> In some of my Mach programming, I've done just that.  [Well, with

>"The behavior is undefined", even if you were (un)lucky enough to have
>it do what you wanted.

Ahh, but it is defined for a given compiler implementation, and since
we're obviously talking about gcc (note the newsgroups) running under
Linux (note the newsgroups), the behaviour is defined as to allow it
to work, so long as you take all or none of the symbols from a given
source file for the library.  Exceptions are made for functions like
exit() and abort() for which gcc knows that they don't return.
Functions like printf() will generate warnings unless your version
uses a similar prototype with arguments based on the format string.

One example of why you might want to redefine printf() to have an
unexpected side-effect would be in developing and testing a new libc.
You might want to record information about the execution of printf()
in global variables which are then examined in the main program.  (Of
course, you're probably better off using a debugger...)

--PC
--
=========================================================================
"It is perhaps only in mathematics that the means of study are also the
objects of study."  _The Handbook of Artificial Intelligence, Vol. 3,
                    page 445.
Technical Details
Message-ID: <4uo8it$ogu@dartvax.dartmouth.edu>
Path: arc1-ca.pugleaf.net!unknown!not-for-mail
References: <4ubnat$75u@freeside.fc.net> <danpop.839504721@news.cern.ch> <vkohklaizj.fsf@atari.connectinc.com> <4udd3i$90k@solutions.solon.com> <vkn3059yhu.fsf@atari.connectinc.com> <320B6599.2C8E@ash.crd.ge.com> <4uh4vh$aj2@dartvax.dartmouth.edu> <320F47BA.39E9@ash.crd.ge.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: crow@coos.dartmouth.edu (Preston F. Crow)
Subject: Re: gcc -O2 bug
Date: 1996/08/12
Message-ID: <4uo8it$ogu@dartvax.dartmouth.edu>
X-Deja-AN: 173771326
references: <4ubnat$75u@freeside.fc.net> <danpop.839504721@news.cern.ch>   <vkohklaizj.fsf@atari.connectinc.com> <4udd3i$90k@solutions.solon.com> <vkn3059yhu.fsf@atari.connectinc.com> <320B6599.2C8E@ash.crd.ge.com> <4uh4vh$aj2@dartvax.dartmouth.edu> <320F47BA.39E9@ash.crd.ge.com>
organization: Dartmouth College, Hanover, NH, USA
newsgroups: comp.unix.programmer,gnu.gcc.help,comp.os.linux.development.apps,comp.lang.c