Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP Path: utzoo!utgpu!water!watmath!clyde!rutgers!husc6!cmcl2!brl-adm!brl-smoke!gwyn From: gwyn@brl-smoke.UUCP Newsgroups: comp.lang.c Subject: Re: VAX/VMS C and Message-ID: <6419@brl-smoke.ARPA> Date: Sat, 12-Sep-87 15:23:40 EDT Article-I.D.: brl-smok.6419 Posted: Sat Sep 12 15:23:40 1987 Date-Received: Sun, 13-Sep-87 08:35:34 EDT References: <9226@brl-adm.ARPA> Reply-To: gwyn@brl.arpa (Doug Gwyn (VLD/VMB) ) Organization: Ballistic Research Lab (BRL), APG, MD. Lines: 38 In article <9226@brl-adm.ARPA> RMANGALD%CLARKU.BITNET@wiscvm.wisc.EDU writes: >Why go to all this trouble when you can use a cast, as in: > f((float) n); This doesn't work -- the float-valued expression is widened to double, so the cast has no practical effect. >Could someone explain what "function prototypes" are? The proposed ANSI C standard adopted Bjarne Stroustrup's method for declaring functions. The main difference from "old C" is that a function declaration may (and normally would) specify parameter types as well as return value type. For example: #if __STDC__ /* ANSI C */ extern int atoi( const char *s ); #else /* old C */ extern int atoi(); #endif (The identifier on the parameter can be omitted.) There are rules for what happens when old-style and prototype-style declarations collide, but it is intended that new code always use prototypes. There are several advantages to function prototypes: (a) provides an opportunity to eliminate parameter widening (b) provides the necessary hook for more general varargs implementation (e.g. when the first N parameters would normally be passed in registers) (c) allows automatic coercion of parameter types (I don't like this one, but many people do) (d) permits/requires better compile-time type checking (e) code is more self-documenting The main disadvantage is that it's different from what we already were using. However, the old style is being "grandfathered in" in such a way that this should rarely be a problem. Notice that the example above takes advantage of ANSI C if it's available but works with old C too; you don't normally need to change old code to do this, but it is advisable to use this method for new code.