3.3 C Weirdness

David B.Anderson davea at quasar.wpd.sgi.com
Tue Sep 25 08:38:46 AEST 1990


In article <761 at sun13.scri.fsu.edu> pepke at 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 <function name> 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 at sgi.com ]
[``What can go wrong?''                          --Calvin and Hobbes]



More information about the Comp.sys.sgi mailing list