home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #20 / NN_1992_20.iso / spool / comp / sys / mac / programm / 15023 < prev    next >
Encoding:
Text File  |  1992-09-07  |  1.5 KB  |  38 lines

  1. Path: sparky!uunet!sun-barr!ames!haven.umd.edu!darwin.sura.net!jvnc.net!rutgers!zeus.ieee.org!fsbbs!f204.n2603.z1.ieee.org!Tommy.Brown
  2. From: Tommy.Brown@f204.n2603.z1.ieee.org (Tommy Brown)
  3. Newsgroups: comp.sys.mac.programmer
  4. Subject: #pragma once whoes!!! Plea for help!
  5. Message-ID: <15889.2AA7EC08@zeus.ieee.org>
  6. Date: 3 Sep 92 13:49:01 GMT
  7. Sender: news
  8. Organization: FidoNet node 1:2603/204 - Not Even Odd, Forest Hills NY
  9. Lines: 27
  10.  
  11. The #pragma once directive, as I believe it says in the C manual (but I'm not
  12. sure, I might have read it somewhere else) only applies once per source file.
  13. So for example, you created file.c. File.c #includes header1.h and header2.h.
  14. In addition, header2.h ALSO #includes header1.h. Normally, you'd get a
  15.  
  16. compiler error ("xxx is already defined" -- NOT a linker error, though). If
  17.  
  18. you have the #pragma once directive at the top of the header1.h, it will only
  19. be included once IN THAT SOURCE FILE. However, there is nothing preventing
  20.  
  21. another source file from #including header1.h again.
  22.  
  23. It sounds as if you are allocating data in a header file, which is not a good
  24. idea for the above reason. If you're allocating variables, allocate them in a
  25. source file and then add "extern" to your header file. So for example,
  26. instead
  27.  of declaring
  28. int gGlobal
  29. in your header file, declare
  30. extern int gGlobal
  31. in your header and declare "int gGlobal" in another source file, perhaps
  32.  
  33. called Globals.c. Hope that helped! 
  34.  
  35. --  
  36. =*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=
  37.  Tommy Brown - Internet: Tommy.Brown@f204.n2603.z1.ieee.org
  38.