Subject: Re: C problems (was Re: compiling metamail)
Message-ID: <unccg9s@sgi.sgi.com>
Date: 10 Jan 93 22:01:04 GMT
Sender: davea@quasar.mti.sgi.com
Organization: Silicon Graphics, Inc. Mountain View, CA
Lines: 40
In article <1993Jan10.004920.13004@biome.bio.ns.ca> silvert@biome.bio.dfo.ca (Bill Silvert) writes:
>Thanks for the one posting that suggested a solution. However, I found
>the answer, and since it is a common one I felt a further posting on the
>subject is called for.
>
>In this case and others, a file contains this sort of code:
>
> ...
> x = DoSomething(...);
> ...
>
>static int DoSomething(...) { ... }
>
>On an SGI system this causes DoSomething to be an unsatisfied external
>unless the function occurs before the invocation, or at least is
>declared before it is invoked. Apparently on other systems this is
>acceptable.
The 3.10 ANSI (I think it is 4.1-IDO) says:
accom: Warning 338: davea2.c, line 8: Linkage conflict. Identifier "x" extern in local scope yet static at file scope. Put declaration at file scope before existing references/declarations.
{
^
So at least you do get a warning before link time with that version.
>I don't know whether the SGI touchiness agrees with the standard, but
I believe that this falls into "undefined behavior".
I don't have a copy of the Standard at home to quote chapter and verse.
But I agree this compiler behavior is unfriendly.
>this is a real pain. Does anyone have a general solution?
No (sorry). The C compiler for the next major release gives a warning
for this but connects the call and the definition so "DoSomething" is