home *** CD-ROM | disk | FTP | other *** search
- Newsgroups: comp.lang.c++
- From: nikki@trmphrst.demon.co.uk (Nikki Locke)
- Path: sparky!uunet!pipex!demon!trmphrst.demon.co.uk!nikki
- Subject: Re: Is calling a function to assign a value to a static global legal?
- Reply-To: nikki@trmphrst.demon.co.uk
- References: <34726@sales.GBA.NYU.EDU>
- Distribution: world
- X-Mailer: cppnews $Revision: 1.30 $
- Organization: Trumphurst Ltd.
- Lines: 54
- Date: Tue, 5 Jan 1993 18:15:50 +0000
- Message-ID: <726282950snx@trmphrst.demon.co.uk>
- Sender: usenet@demon.co.uk
-
- In article <34726@sales.GBA.NYU.EDU> wlee@sales.GBA.NYU.EDU (Wai-Shing Lee) writes:
- > 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.
-
- It is legal to do this in C++, but not in C.
-
- > extern "C"
- > {
- > #include <alloc.h>
- > }
- >
- > static int *pointer ;
- > static int initialized=findvideomemory() ;
-
- Not legal C++, because findvideomemory is not defined in alloc.h, or in
- your program so far. I assume this is because you have just left out the
- declaration in your posting.
-
- Not legal C (unless findvideomemory() is a macro whose value can be
- determined at compile time).
-
- > static int makepointer(void)
- > {
- > pointer=(int*)calloc(10, sizeof(char)) ;
-
- You should return a value from this function, as it is declared to return
- an integer.
-
- > }
-
- I don't see the relevence of this function - it is not accessed anywhere
- else in your example.
-
- > 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?
-
- I don't understand why makepointer is called - I can't see any calls to it
- anywhere in the example given.
-
- I don't suppose "findvideopointer" is a type for "makepointer" is it ?
-
- --
- Nikki Locke,Trumphurst Ltd.(PC and Unix consultancy) nikki@trmphrst.demon.co.uk
- trmphrst.demon.co.uk is NOT affiliated with ANY other sites at demon.co.uk.
-