home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1993 #1 / NN_1993_1.iso / spool / comp / lang / cplus / 18720 < prev    next >
Encoding:
Text File  |  1993-01-05  |  2.4 KB  |  69 lines

  1. Newsgroups: comp.lang.c++
  2. From: nikki@trmphrst.demon.co.uk (Nikki Locke)
  3. Path: sparky!uunet!pipex!demon!trmphrst.demon.co.uk!nikki
  4. Subject: Re: Is calling a function to assign a value to a static global legal?
  5. Reply-To: nikki@trmphrst.demon.co.uk
  6. References: <34726@sales.GBA.NYU.EDU>
  7. Distribution: world
  8. X-Mailer: cppnews $Revision: 1.30 $
  9. Organization: Trumphurst Ltd.
  10. Lines: 54
  11. Date: Tue, 5 Jan 1993 18:15:50 +0000
  12. Message-ID: <726282950snx@trmphrst.demon.co.uk>
  13. Sender: usenet@demon.co.uk
  14.  
  15. In article <34726@sales.GBA.NYU.EDU> wlee@sales.GBA.NYU.EDU (Wai-Shing Lee) writes:
  16. >    I want to initialize a static global at run-time but I don't want to
  17. > have to have a programmer using my modules to have to call some init() funciton
  18. > at the begining of thier main().
  19. > I can get this to compile under Borland C++ 3.1, but only if it is compiled as
  20. > C++, it doesn't like it if it is compiled as plain Borland C.
  21.  
  22. It is legal to do this in C++, but not in C. 
  23.  
  24. > extern "C"
  25. > {
  26. > #include <alloc.h>
  27. > }
  28. > static int *pointer ;
  29. > static int initialized=findvideomemory() ;
  30.  
  31. Not legal C++, because findvideomemory is not defined in alloc.h, or in 
  32. your program so far. I assume this is because you have just left out the 
  33. declaration in your posting. 
  34.  
  35. Not legal C (unless findvideomemory() is a macro whose value can be 
  36. determined at compile time).
  37.  
  38. > static int makepointer(void)
  39. > {
  40. >     pointer=(int*)calloc(10, sizeof(char)) ;
  41.  
  42. You should return a value from this function, as it is declared to return 
  43. an integer.
  44.  
  45. > }
  46.  
  47. I don't see the relevence of this function - it is not accessed anywhere 
  48. else in your example.
  49.  
  50. > The variable "initialized" is junk, but I could just as easily return a value
  51. > from makepointer(), but I have more stuff going on in makepointer() than
  52. > appears here.
  53. > I've traced it and sure enough makepointer() is called and pointer is assigned
  54. > a value before main() even starts.  Is the portable, legal.  I didn't look
  55. > to hard in my C++ book, but there weren't any obvious answers.  Is this
  56. > C++, C or something I should stay away from?
  57.  
  58. I don't understand why makepointer is called - I can't see any calls to it
  59. anywhere in the example given.
  60.  
  61. I don't suppose "findvideopointer" is a type for "makepointer" is it ?
  62.  
  63. -- 
  64. Nikki Locke,Trumphurst Ltd.(PC and Unix consultancy) nikki@trmphrst.demon.co.uk
  65. trmphrst.demon.co.uk is NOT affiliated with ANY other sites at demon.co.uk.
  66.