Recursive #includes

Geoff Rimmer geoff at cs.warwick.ac.uk
Sun Mar 12 03:11:29 AEST 1989


In article <9804 at smoke.BRL.MIL> gwyn at smoke.BRL.MIL (Doug Gwyn ) writes:
> In article <7488 at june.cs.washington.edu> ka at june.cs.washington.edu (Kenneth Almquist) writes:
> >I've been told that incomplete types cannot be used in function prototypes.
> 
> I couldn't find such a prohibition in the pANS.
> (But maybe it's there and I missed it.)

gcc will not allow it:

Script started on Sat Mar 11 17:04:06 1989
--geoff at emerald%   cat str.c

static void function (struct egg * a);

struct egg { int number1; float number2; };

static void function (struct egg * a)
{
        printf("In function with [%d,%f]\n",a->number1,a->number2);
}

extern void main (void)
{
        struct egg aa;
        aa.number1=23;
        aa.number2=12.345;
        function(&aa);
}

--geoff at emerald%   gcc -v
gcc version 1.34
--geoff at emerald%   gcc -ansi -pedantic str.c
str.c:1: warning: `struct egg' declared inside parameter list
str.c: In function function:
str.c:6: conflicting types for `function'
str.c:1: previous declaration of `function'
--geoff at emerald%   exit

script done on Sat Mar 11 17:05:06 1989

The strange thing is that it doesn't barf on the 

	struct void function (struct egg *a);

line, even though the structure is as yet undefined.  The problem is
when it compares the types of the function's arguments, and sees that
in the call to the function, the argument is type (struct egg *) and
in the declaration it is unknown.

Is this a problem with gcc, or does this happen with all ANSI compilers?

Geoff

	------------------------------------------------------------
	Geoff Rimmer, Computer Science, Warwick University, England.
			geoff at uk.ac.warwick.emerald

		"Ahhh, bonjour, monsieur."
		"Sod off."
			- Blackadder 3.
	------------------------------------------------------------



More information about the Comp.lang.c mailing list