Path: utzoo!utgpu!jarvis.csri.toronto.edu!mailrus!ncar!tank!shamash!com50!jhereg!mark From: mark@jhereg.Jhereg.MN.ORG (Mark H. Colburn) Newsgroups: comp.lang.c Subject: Re: TLINK errors (cc/lint were clean) Message-ID: <508@jhereg.Jhereg.MN.ORG> Date: 2 Feb 89 17:18:17 GMT References: <44100021@hcx1> Reply-To: mark@jhereg.MN.ORG (Mark H. Colburn) Organization: Minnetech Consulting, Inc., St. Paul MN Lines: 45 In article <44100021@hcx1> ldh@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 >#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@jhereg.mn.org there's no black and there's no white."