home *** CD-ROM | disk | FTP | other *** search
- 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
- From: Tommy.Brown@f204.n2603.z1.ieee.org (Tommy Brown)
- Newsgroups: comp.sys.mac.programmer
- Subject: #pragma once whoes!!! Plea for help!
- Message-ID: <15889.2AA7EC08@zeus.ieee.org>
- Date: 3 Sep 92 13:49:01 GMT
- Sender: news
- Organization: FidoNet node 1:2603/204 - Not Even Odd, Forest Hills NY
- Lines: 27
-
- The #pragma once directive, as I believe it says in the C manual (but I'm not
- sure, I might have read it somewhere else) only applies once per source file.
- So for example, you created file.c. File.c #includes header1.h and header2.h.
- In addition, header2.h ALSO #includes header1.h. Normally, you'd get a
-
- compiler error ("xxx is already defined" -- NOT a linker error, though). If
-
- you have the #pragma once directive at the top of the header1.h, it will only
- be included once IN THAT SOURCE FILE. However, there is nothing preventing
-
- another source file from #including header1.h again.
-
- It sounds as if you are allocating data in a header file, which is not a good
- idea for the above reason. If you're allocating variables, allocate them in a
- source file and then add "extern" to your header file. So for example,
- instead
- of declaring
- int gGlobal
- in your header file, declare
- extern int gGlobal
- in your header and declare "int gGlobal" in another source file, perhaps
-
- called Globals.c. Hope that helped!
-
- --
- =*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=
- Tommy Brown - Internet: Tommy.Brown@f204.n2603.z1.ieee.org
-