Related articles |
---|
A lesson for compiler warning writers Garrett.Wollman@UVM.EDU (1992-06-10) |
Re: A lesson for compiler warning writers mcdaniel@adi.com (1992-06-12) |
Re: A lesson for compiler warning writers tmb@arolla.idiap.ch (1992-06-17) |
Re: A lesson for compiler warning writers maniattb@cs.rpi.edu (1992-06-17) |
Re: A lesson for compiler warning writers stephen@estragon.uchicago.edu (1992-06-18) |
Re: A lesson for compiler warning writers arnold@cc.gatech.edu (1992-06-18) |
Re: A lesson for compiler warning writers xjam@cork.CS.Berkeley.EDU (1992-06-18) |
[14 later articles] |
Newsgroups: | comp.compilers |
From: | Garrett.Wollman@UVM.EDU (Garrett Wollman) |
Keywords: | design, errors |
Organization: | University of Vermont, EMBA Computer Facility |
References: | <19920609091040SEB1525@MVS.draper.com> |
Date: | Wed, 10 Jun 1992 02:28:54 GMT |
[Background: Standard C allows a user to declare a function as accepting a
pointer to a structure which has not been defined yet, with the structure
being defined within the scope of the function declaration. Someone on
comp.lang.c asked why their would not accept code of the form:
extern int blat(struct foo *);
struct foo { int bar; } baz;
int main() { return blat(&baz); }
complaining that the argument types in declaration and call were not
compatible. Steve Summit explained what was wrong, and here is my reply
to him.]
I believe that at least one of the compilers that I use has a nice,
verbose message explaining what's wrong. Let's see...
Here it is...
wollman@trantor$ gcc -c foo.c
foo.c:1: warning: `struct foo' declared inside parameter list
foo.c:1: warning: its scope is only this definition or declaration,
foo.c:1: warning: which is probably not what you want.
foo.c: In function `main':
foo.c:3: warning: passing arg 1 of `blat' from incompatible pointer type
wollman@trantor$
Now if only there was a GCC port for the 370... For that matter, if only
other compiler vendors could take the lesson from GCC and emit helpful,
user-controllable diagnostics. GCC doesn't always produce the best code,
but there's nothing like a trip through the list of possible warning
options to GCC to demonstrate coding errors and portability problems...
IBM's XL C isn't bad as far as actually implementing ANSI strictures, and
MIPS/SGI C will quote chapter and verse from the Standard, but GCC will
tell you when you do something that isn't illegal but <bold>is</bold>
questionable.
-GAWollman
--
Garrett A. Wollman = wollman@uvm.edu =
= uvm-gen!wollman =
--
Return to the
comp.compilers page.
Search the
comp.compilers archives again.