home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1993 #3 / NN_1993_3.iso / spool / alt / msdos / programm / 3213 < prev    next >
Encoding:
Text File  |  1993-01-23  |  1.9 KB  |  45 lines

  1. Newsgroups: alt.msdos.programmer
  2. Path: sparky!uunet!zaphod.mps.ohio-state.edu!sdd.hp.com!hpscit.sc.hp.com!icon.rose.hp.com!wes
  3. From: wes@hpsmo100.rose.hp.com (Westley)
  4. Subject: Re: Problem with TurboC++ ???
  5. Sender: news@icon.rose.hp.com (News Administrator)
  6. Message-ID: <C1A0IC.I0G@icon.rose.hp.com>
  7. Date: Fri, 22 Jan 1993 22:15:48 GMT
  8. References: <1j80c6INN456@festus.ksu.ksu.edu>
  9. Organization: one end of the world
  10. X-Newsreader: TIN [version 1.1.8 PL6]
  11. Lines: 32
  12.  
  13. Steven D. Marcotte (sdoran@festus.ksu.ksu.edu) wrote:
  14. >
  15. >    I ran across a problem when trying to compile a program the
  16. >other day.  Turbo C seems to think that when I define a varible in 
  17. >a header file, it should associate it with all the files and the 
  18. >compiler comes back and tells me something like:
  19. >    for file bar.c _x already declared in foo.c
  20. >
  21. [...]
  22. >
  23. >    It compiles correctly on the school's UNIX box using cc and gcc
  24. >I just can't get Turbo C++ to work right.  Any suggestions to why it is 
  25. >doing this?  Thanks...
  26.  
  27. I have seen a similar behaviour ONLY when both files (foo.c and bar.c) are
  28.  included in the same 'project'.  Turbo C will completely compile all files
  29.  related by the project list and then try to link them.  If you have an
  30.  #include that declares a variable, it will be declared in ALL files that
  31.  refer to that #include.  Then the link process will find multiply declared
  32.  variables.  
  33. One way to avoid this is to NOT have any variable declarations in generic
  34.  #include files.  In other words, declare any variable IN each file, not in
  35.  an #include.  ONLY one of the files will need to do the actual declaration,
  36.  the others will refer to that declaration with 'extern' put in front of
  37.  their declarations.
  38. The 'project' option in Turbo C is pretty neat, but can be dangerous if you
  39.  don't understand it completely (as I did the first few times I tried to use
  40.  it).  Good luck with your project.
  41.  
  42.     Westley
  43.     wes@hpsmo100.rose.hp.com
  44.