Article View: comp.unix.programmer
Article #3678Re: gcc -O2 bug
From: Lawrence Kirby
Date: Sat, 10 Aug 1996 00:00
Date: Sat, 10 Aug 1996 00:00
39 lines
2635 bytes
2635 bytes
In article <4uh4vh$aj2@dartvax.dartmouth.edu>
crow@coos.dartmouth.edu "Preston F. Crow" writes:
>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
>could have stupidly defined his own function of the same name,
>overriding the expected behaviour of the version in libc.
No, this isn't how it works. printf is a reserved identifier with external
linkage which means that if you try to define it yourself with external
linkage the behaviour is undefined. Also if you include stdio.h you can't
define printf yourself at file scope, for example you can't define a
static printf function. The standard is deliberately worded so that the
implementation can make assumptions about standard library functions. This
allows compilers, for example, to implicitly inline memcpy, strcpy etc.
>In some of my Mach programming, I've done just that. [Well, with
>different functions, where the normal version had problems, but
>still...]
It may work on your compiler but the language gives you no guarantees
at all that it will.
>Never expect a compiler to be smart, but always be prepared for it to
>outsmart you.
Exactly.
--
-----------------------------------------
Lawrence Kirby | fred@genesis.demon.co.uk
Wilts, England | 70734.126@compuserve.com
-----------------------------------------
Technical Details
Message-ID:
<839694877snz@genesis.demon.co.uk>Path:
arc1-ca.pugleaf.net!unknown!not-for-mailReferences:
<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>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: Lawrence Kirby <fred@genesis.demon.co.uk> Subject: Re: gcc -O2 bug Date: 1996/08/10 Message-ID: <839694877snz@genesis.demon.co.uk> X-Deja-AN: 173391328 x-nntp-posting-host: genesis.demon.co.uk 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> x-mail2news-path: genesis.demon.co.uk organization: none reply-to: fred@genesis.demon.co.uk newsgroups: comp.unix.programmer,gnu.gcc.help,comp.os.linux.development.apps,comp.lang.c