Path: utzoo!attcan!uunet!pilchuck!dataio!fnx!nazgul!bright From: bright@nazgul.UUCP (Walter Bright) Newsgroups: comp.lang.c Subject: Re: ANSI C prototypes Message-ID: <151@nazgul.UUCP> Date: 8 Nov 90 18:53:13 GMT References: <1005@christopher-robin.cs.bham.ac.uk> <1906@necisa.ho.necisa.oz> <1990Nov2.030556.27759@ccu.umanitoba.ca> <3933.27353319@cc.helsinki.fi> Reply-To: bright@nazgul.UUCP (Walter Bright) Organization: Zortech, Seattle Lines: 35 In article <3933.27353319@cc.helsinki.fi> jaakola@cc.helsinki.fi writes: / static void auxiliary_func(a) /* private helper-function */ / int a; / { / } / void visible_fun(b) / int b; / { / ... / auxiliary_func(b+1); /* should be checked */ / ... / } / /The point is, why should I have to tell the compiler twice the type of /auxiliary_func? The prototype should be necessary only if I make a /forward reference to make it easier for the compiler to check types in a /single pass. I think the function definition tells unambiguously the /types, so I should not have to watch warnings such as "function /definition used as a prototype" (Microsoft C 5.1). In Zortech, the first function declaration does result in a prototype being declared (internal to the compiler) and all future uses of auxiliary_func are checked against that prototype. In fact, the first use of a function, in the absence of a prototype, causes a prototype to be generated for that function based on the default argument promotion rules. This is not ANSI behavior, and can be disabled with the -P switch, but is very useful in checking for errors in old K&R code. The -r switch, strict prototyping, is also available, which enforces a rule that all uses of a function must have a prototype in scope for it. I use this switch for all my code, and recommend its use, as it results in the bugs being caught at the earliest possible time (when they are the cheapest to fix!).