Path: utzoo!utgpu!news-server.csri.toronto.edu!cs.utexas.edu!sun-barr!ames!sgi!davea@quasar.wpd.sgi.com From: davea@quasar.wpd.sgi.com (David B.Anderson) Newsgroups: comp.sys.sgi Subject: Re: 3.3 C Weirdness Message-ID: <70109@sgi.sgi.com> Date: 24 Sep 90 22:38:46 GMT References: <761@sun13.scri.fsu.edu> Sender: guest@sgi.sgi.com Reply-To: davea@quasar.UUCP (David B.Anderson) Organization: Silicon Graphics, Inc., Mountain View, CA Lines: 51 In article <761@sun13.scri.fsu.edu> pepke@gw.scri.fsu.edu (Eric Pepke) writes: >There is a weirdness in the C that comes with 3.3 when the -prototypes >argument is supplied. > >I like to put prototypes in the .h file associated with each .c file, and >then use old style definitions in the .c file. That way, if I want to >compile on a 3030, I just hack out the prototypes and it compiles fine. > >With the new C, however, I sometimes get some odd error messages of the >form > >old/new style declaration and definition of argument <#> >mismatch: change the definition to the new (function prototype) style. > >As far as I can tell, this does not in any way affect code generation; This message means that you are doing something that violates the ANSI C rule that, when mixing a prototype with an old-style definition: ``the type of each parameter shall be compatible with the type that results from the appliation of the default argument promotions.'' So that would mean declaring the argument as int, not char (everywhere). (This compiler is not an ANSI C compiler but it does enforce some basic ANSI rules for function prototypes.) So: int x(char); int x(z) char z; { } is an error,while int x(char); int x(char z) { } is correct. The compiler is complaining because a) the usage in error will generate code that will not work for some (non-sgi) machines for char, short, unsigned char, unsigned short. b) the resulting code will defininitely not work on our machines if one has int x(float); int x(y) float y; { } since any call seeing the prototype will pass a float, while the function definition expects a double (after K&R type rewriting to double). The compiler is just trying to keep you from writing non-portable/erroneous code. It's for your own good :-). Hope this helps. [ David B. Anderson Silicon Graphics (415)335-1548 davea@sgi.com ] [``What can go wrong?'' --Calvin and Hobbes]