TLINK errors (cc/lint were clean)

Maarten Litmaath maart at cs.vu.nl
Fri Feb 3 13:37:03 AEST 1989


ldh at hcx1.SSD.HARRIS.COM writes:
\header.h:
\#include <stdio.h>
\#include <       >  		(a bunch of includes)

\int a,b,c,d,e,f,g,h;
\float i,j,k,l,m,n,o,p;
\char q,r,s,t,u,v;

Aaaaaaaaargh! A header file should NEVER contain variable DEFINITIONS!
It should only contain `#define's and variable DECLARATIONS.
So:
	extern	int	a, ...;
	extern	float	i, ...;
	extern	char	q, ...;

The definitions are handled in an accompanying file `header.c'.
A nice solution to prevent redundancy (and error-proneness):

	#ifndef	HEADER_H
	#define		HEADER_H

	#ifndef	EXTERN
	#define		EXTERN		extern
	#else	EXTERN
	#define		INIT
	#endif	!EXTERN

	EXTERN	int	a, ...;
	EXTERN	float	i, ...;
	EXTERN	char	q[]
	#ifdef	INIT
			= "hey babe!"
	#endif	INIT
			;

	#endif	!HEADER_H

In `foo.c':

	#include	"header.h"

In `header.c':

	#define		EXTERN
	#include	"header.h"
-- 
 "Does she play, er, tennis?          |Maarten Litmaath @ VU Amsterdam:
             Wink wink, notch notch!" |maart at cs.vu.nl, mcvax!botter!maart



More information about the Comp.lang.c mailing list