[prog] Elementary 'C' question

David Sumbler david at aeolia.co.uk
Sun Nov 14 22:37:40 EST 2004


I have been looking at the code of Ed James's excellent little game
'ATC' - part of the BSD Games package.  I am doing this partly because
I would like to write an OPL version for my Psion 5mx handheld
computer, and also as a tool to improve my lamentable understanding of
C.

But I am a little mystified by the following, which is part of the
'main.c' file:

extern FILE	*yyin;

int
main(ac, av)
 	int	 ac;
 	char	*av[];
{
 	const char		*file = NULL;
...

 	if (file == NULL || read_file(file) < 0)
 		exit(1);
...
}

int
read_file(s)
 	const char	*s;
{
...
 	yyin = fopen(s, "r");
 	if (yyin == NULL) {
...
 	}
...
 	fclose(yyin);
...
}


The '...' lines are chunks of code I have omitted.

These are all the mentions of 'yyin' anywhere in the file, and there
is no mention of it anywhere else in the atc files or any of the other
bsd-games files.

My question is: why is 'yyin' shown as 'extern', since it only seems
to be mentioned in this file, and is presumably defined by the 'extern
FILE *yyin' line?

Sorry if this is a particularly stupid question.

David

--


More information about the Programming mailing list