TLINK errors (cc/lint were clean)

Mark H. Colburn mark at jhereg.Jhereg.MN.ORG
Fri Feb 3 03:18:17 AEST 1989


In article <44100021 at hcx1> ldh at hcx1.SSD.HARRIS.COM writes:
>Have a modularized program lint/cc do not object to the various modules ... TC2
>on the other hand does.
>
>basically:
>
>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;

Each of these declarations reserve a slot of memory for the variable being
declared.  The amount of memory, obviously depends on the type of the
declaration.  You later include this file into mutliple compilation units
(modules).  The result is:

	main.c:
	int a,b,c,d....;

	module_a:
	int a,b,c,d....;

Which saves slot of memory for "int a,b..." in both main.c and module_a.c.
When you try to link the programs together, the linker complains.  What you
should have, if you want a,b,c,d, etc. to be global variables is:

	main.c:
	int a,b,c,d...;

	module_a:
	extern int a,b,c,d....;

The fact the your unix compiler/linker does not catch this error is
actually just sloppy play on your compiler vendors part.  Multiple
declarations of this sort usually indicate a bug in the program somehere.
If the linker does not complain, they can be very difficult to track down.

Hope that this helps.
-- 
Mark H. Colburn                  "Look into a child's eye;
Minnetech Consulting, Inc.        there's no hate and there's no lie;
mark at jhereg.mn.org                there's no black and there's no white."



More information about the Comp.lang.c mailing list