home *** CD-ROM | disk | FTP | other *** search
- Path: sparky!uunet!gatech!rutgers!cmcl2!sales!wlee
- From: wlee@sales.GBA.NYU.EDU (Wai-Shing Lee)
- Newsgroups: comp.lang.c++
- Subject: Static global initialization outside of main() legal?
- Message-ID: <34727@sales.GBA.NYU.EDU>
- Date: 31 Dec 92 06:39:39 GMT
- Organization: NYU
- Lines: 31
-
-
- I want to initialize a static global at run-time but I don't want to
- have to have a programmer using my modules to have to call some init() funciton
- at the begining of thier main().
-
- I can get this to compile under Borland C++ 3.1, but only if it is compiled as
- C++, it doesn't like it if it is compiled as plain Borland C.
-
- extern "C"
- {
- #include <alloc.h>
- }
-
- static int *pointer ;
- static int initialized=findvideomemory() ;
-
- static int makepointer(void)
- {
- pointer=(int*)calloc(10, sizeof(char)) ;
- }
-
- The variable "initialized" is junk, but I could just as easily return a value
- from makepointer(), but I have more stuff going on in makepointer() than
- appears here.
-
- I've traced it and sure enough makepointer() is called and pointer is assigned
- a value before main() even starts. Is the portable, legal. I didn't look
- to hard in my C++ book, but there weren't any obvious answers. Is this
- C++, C or something I should stay away from?
-
- Thanks
-