Article View: gnu.gcc.bug
Article #2332gcc prototype enforcer
From: Geoff Rimmer
Date: Sat, 18 Feb 1989 07:05
Date: Sat, 18 Feb 1989 07:05
62 lines
2722 bytes
2722 bytes
Earlier this year, Paul Hudson summarised to thsi newsgroup, the
responses he got to his request for desired warnings for gcc.
One thing that I didn't see mentioned was a warning that would
complain like hell if you use *ANY* function (including C library
functions) without giving it a function prototype beforehand. Our
current version (gcc v1.32) will complain (with -Wall) if no mention
whatsoever is made of the function, and rightly so. However, if the
function is declared in the old style, eg. (from /usr/include/stdio.h)
extern char *fgets();
gcc doesn't say a thing.
The reason why I would like gcc to shout when it sees a situation like
this, is because I was writing a program and used 'fgets'. Unfortunately,
I accidentally swapped the first 2 parameters around, that is to say I put
while (fgets(BUFSIZ,buffer,fpr)) {...}
rather than
while (fgets(buffer,BUFSIZ,fpr)) {...}
Now, I had included <stdio.h>, so gcc knew about fgets. However in my
protos.h file (where I keep a list of library functions), I had mistakenly
omitted fgets(). So, the program compiled fine, but I got a segmentation
fault when I ran it.
If gcc would print a warning whenever it sees a function that has not
been declared as a *prototype*, I would have added the missing
extern fgets (char *, int, FILE *);
and then on re-compilation, it would have been able to spot that the
arguments were not correctly ordered.
Presumably when we get full ANSI C, all the standard header files will
have the prototypes and so this situation will become less common.
However, it would still be very useful for converting old-style C
programs to ANSI C - making sure that EVERY function you write has its
own prototype.
If it would be possible, I'd like to see this feature in the next
version of gcc.
Thanks for listening!
geoff M-b M-c
------------------------------------------------------------
Geoff Rimmer, Computer Science, Warwick University, England.
geoff@uk.ac.warwick.emerald
"Filthy, if this is supposed to be some sort of joke..."
"Then it'll be the first on the show this week!!"
"Shut up, Eddie. The show's only just begun, and we've had
some super laughs already."
- Filthy, Rich and Catflap, 1986.
------------------------------------------------------------
Technical Details
Message-ID:
<1261@ubu.warwick.UUCP>Path:
arc1-ca.pugleaf.net!utzoo!telly!attcan!uunet!mcvax!ukc!warwick!geoffShow Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!utzoo!telly!attcan!uunet!mcvax!ukc!warwick!geoff From: geoff@warwick.UUCP (Geoff Rimmer) Newsgroups: gnu.gcc.bug Subject: gcc prototype enforcer Message-ID: <1261@ubu.warwick.UUCP> Date: 18 Feb 89 07:05:32 GMT Sender: news@warwick.UUCP Reply-To: geoff@warwick.UUCP (Geoff Rimmer) Organization: Computer Science, Warwick University, UK Lines: 62