new style declarations OK for old style definitions?

Geoffrey Rogers grogers at convex.com
Thu Apr 4 00:18:49 AEST 1991


In article <14590 at life.ai.mit.edu> tmb at ai.mit.edu writes:
>K&R/2 is a little vague on the following question: under what
>circumstances is it legal to declare using new-style syntax a
>separately compiled function that was compiled with an old-style
>definition. 
>
>Is it sufficient to use only promoted arguments in the new-style
>declaration?

Yes. If you don't use the default promotion types you will have
problems. If you have a old-style definition of:

int xyz(a,b,c)
	char  a;
	short b;
	float c;
{
	return 0;
}

The new-style declaration is:

extern int xyz(int a, int b, double c);

>Conceivably, the whole calling sequence for old style and new style
>definitions could differ. Is it legal for the compiler to choose
>completely incompatible calling sequences for old-style and new-style
>declarations? 

Yes. If you said one thing and did another the compiler would have no way
of known that you were lying to it, unless the new-style declaration was also
in the same file as the old-style definition.


+------------------------------------+---------------------------------+
| Geoffrey C. Rogers   		     | "Whose brain did you get?"      |
| grogers at convex.com                 | "Abbie Normal!"                 |
| {sun,uunet,uiucdcs}!convex!grogers |                                 |
+------------------------------------+---------------------------------+



More information about the Comp.lang.c mailing list