home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1993 #3 / NN_1993_3.iso / spool / comp / lang / cplus / 20092 < prev    next >
Encoding:
Text File  |  1993-01-28  |  1.4 KB  |  50 lines

  1. Newsgroups: comp.lang.c++
  2. Path: sparky!uunet!math.fu-berlin.de!ira.uka.de!scsing.switch.ch!univ-lyon1.fr!ghost.dsi.unimi.it!rpi!zaphod.mps.ohio-state.edu!pacific.mps.ohio-state.edu!cis.ohio-state.edu!news.sei.cmu.edu!fs7.ece.cmu.edu!crabapple.srv.cs.cmu.edu!POPTART.GRAPHICS.CS.CMU.EDU!baraff
  3. From: baraff+@cs.cmu.edu (David Baraff)
  4. Subject: static constructor order question
  5. Message-ID: <baraff.728224300@POPTART.GRAPHICS.CS.CMU.EDU>
  6. Sender: news@cs.cmu.edu (Usenet News System)
  7. Nntp-Posting-Host: poptart.graphics.cs.cmu.edu
  8. Organization: School of Computer Science, Carnegie Mellon
  9. Date: Thu, 28 Jan 1993 12:31:40 GMT
  10. Lines: 38
  11.  
  12. I just switched to a compiler where it appears static constructors
  13. from libraries *aren't* called first, and I realized the
  14. following: (so my question is, is the following correct?)
  15.  
  16. Suppose "class helper" is a class with a constructor.
  17. Then suppose
  18.  
  19. class foo {
  20.     static hlper important;
  21.  
  22.     foo() { ... code depending on 'important' having been constructed }
  23.     ...
  24. };
  25.  
  26. Now suppose that I have a nonlocal static foo i.e.
  27.  
  28. /* file.c */
  29. #include    <whatever.h>
  30.  
  31. foo my_object;
  32.  
  33. ---------
  34. So when my program begins, I expect 'my_object' to be constructed
  35. before main starts executing (or at least before 'my_object'
  36. is ever used). But because 'important' is not a member of 'my_object',
  37.  
  38.      there is no guarantee that 'important' will have been
  39.       constructed before 'my_object' is??
  40.  
  41. Is that right?
  42.  
  43.     -- David Baraff
  44.     baraff@cs.cmu.edu
  45.  
  46.  
  47.  
  48.  
  49.  
  50.