Article View: gnu.gcc.help
Article #53413Re: require prototypes?
From: Ian Lance Taylor
Date: Wed, 22 Jan 1992 07:08
Date: Wed, 22 Jan 1992 07:08
49 lines
2559 bytes
2559 bytes
ksedgwic@netcom.COM (Ken Sedgwick) writes:
>Is there a way to make gcc require prototypes for all
>functions?
It depends a bit on what you mean. You can use -Wimplicit to warn
about functions which are used without being declared. You can use
-Wstrict-prototypes to warn about functions which are declared in the
old non-prototype style. I can't think of any warning given for
functions defined (rather than declared) in the old style.
Another thing you might mean is to require a prototype for a function
definition, rather than a function use. Here is a patch we use
locally to do exactly this when compiling with -Wstrict-prototypes. I
sent this to RMS last year sometime, and he said something like this
would go into gcc 2.0. The code is in #ifdef __AMOS__, which you will
want to change. As written, it only warns about externally visible
functions (not static functions) and does not warn about the function
main.
*** ../gcc-1.40/c-decl.c Fri Jun 14 17:19:48 1991
--- c-decl.c Mon Jan 6 12:05:14 1992
***************
*** 1017,1022 ****
--- 1017,1035 ----
}
return t;
}
+
+ #ifdef __AMOS__ /* Warn for functions with no prototypes */
+ /* If this is a function definition for which no prototype has
+ been seen, maybe give a warning, unless it's static. */
+ if (t == 0
+ && TREE_CODE (x) == FUNCTION_DECL
+ && ! TREE_EXTERNAL (x)
+ && TREE_PUBLIC (x)
+ && warn_strict_prototypes
+ && strcmp (IDENTIFIER_POINTER (name), "main"))
+ warning_with_decl (x,
+ "%s: no prototype for externally visible function definition");
+ #endif /* __AMOS__ warn if no prototype */
/* If declaring a type as a typedef, and the type has no known
typedef name, install this TYPE_DECL as its typedef name. */
--
Ian Taylor | ian@airs.com | First to identify quote wins free e-mail message:
``In the end, we found that the only method of communicating with our
landlords, who were living in the same house with us, was to go down
into Florence and send a registered express letter to them.''
Technical Details
Message-ID:
<3356@airs.com>Path:
arc1-ca.pugleaf.net!sparky!uunet!airs!ianReferences:
<1992Jan21.223548.28855ksedgwic@netcom.COM>Show Full Headers
Complete Article Headers
X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 11318c,670ad217a885bb0c X-Google-Attributes: gid11318c,public X-Google-ArrivalTime: 1992-01-21 23:55:59 PST Path: arc1-ca.pugleaf.net!sparky!uunet!airs!ian From: ian@airs.com (Ian Lance Taylor) Newsgroups: gnu.gcc.help Subject: Re: require prototypes? Message-ID: <3356@airs.com> Date: 22 Jan 92 07:08:10 GMT References: <1992Jan21.223548.28855ksedgwic@netcom.COM> Sender: news@airs.com Lines: 49