Variables

M. J. Shannon, Jr. mjs at alice.UUCP
Thu Nov 15 00:03:28 AEST 1984


The way to do what you want is something like this:

/* file libstuff.h: */
extern int globlibfunc0();
extern double globlibvar0;

/* file libstuff.c: */
#include "libstuff.h"
double globlibvar0 = 3.1415926535;
static locallibvar0 = 17;
static int locallibfunc0();

static int
locallibfunc0(x, y, z)
double x, y, z;
{
	x /= y; z /= x;
	return (x < z);
}

int
globlibfunc0(x, y)
double x, y;
{
	return (locallibfunc0(x, y, locallibvar0));
}

/* file main.c: */
#include "libstuff.h"

main()
{
	double x, y;

	(void) scanf("%g,%g\n", &x, &y);
	printf("%d\n", globlibfunc0(x, y);
	exit(0);
}

The magic invloved is the keyword `static', which makes the identifier
local to the file in which it is declared (in which file it must also
be defined).  The header file should contain only aggregate declarations
(struct, union, enum, typedef, etc.) and function declarations, all of
which should be preceded by the keyword `extern' to indicate that they're
not defined here.



More information about the Comp.lang.c mailing list