home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1993 #3 / NN_1993_3.iso / spool / comp / std / cplus / 2108 < prev    next >
Encoding:
Text File  |  1993-01-24  |  1.8 KB  |  58 lines

  1. Path: sparky!uunet!gatech!paladin.american.edu!howland.reston.ans.net!usc!cs.utexas.edu!sun-barr!olivea!charnel!sifon!thunder.mcrcim.mcgill.edu!sobeco!philmtl!vedge!hendrik
  2. From: hendrik@vedge.com (Hendrik Boom)
  3. Newsgroups: comp.std.c++
  4. Subject: initializing several translation units
  5. Message-ID: <1993Jan22.152436.5221@vedge.com>
  6. Date: 22 Jan 93 15:24:36 GMT
  7. Organization: Visual Edge Software Ltd.
  8. Lines: 48
  9.  
  10. ---------------
  11. Translation unit 1:
  12.  
  13. class x{....
  14.     x();
  15.     ....};
  16.  
  17. extern x y;
  18.  
  19. foo(){ .... y ....}
  20.  
  21. Translation unit 2:
  22.  
  23. class x{....
  24.     x();
  25.     ....};
  26.     // same class x as above; presumably both are really in a header file
  27.  
  28. x y;
  29.  
  30. -----------------
  31.  
  32. Can I rely on y being initialized in translation unit 2 by
  33. the constructor x::x() before it is used in translation unit 1?
  34. -- Assuming there is no other dependency of unit 2 on unit 1, of course.
  35.  
  36. The ARM (section 3.4, page 19) suggests in large print that you can:
  37.     The initialization of nonlocal static objects in a translation
  38.     unit is done before the first use of any function or object
  39.     defined in that translation uniot.
  40.  
  41. So the initialization of y in unit 2 should occur before any use of y,
  42. which is defined in unit 2. The ARM doesn't say that the use has to be
  43. in unit 1.
  44.  
  45. The ARM then proceeds undercut this in the small print by suggesting ways
  46. you can accomplish proper initialization order by long, complicated coding.
  47. Is the small print an advice to the implementer (in which case the user
  48. can rely on proper initialization of y) or advice to the user
  49. (in which he can't)?
  50.  
  51. Is the situation different if foo() is called from the initializer of
  52. another nonlocal static object in unit 1?
  53. -- 
  54. -------------------------------------------------------
  55. Try one or more of the following addresses to reply.
  56. at work:    hendrik@vedge.com,  iros1!vedge!hendrik
  57. at home:    uunet!ozrout!topoi!hendrik
  58.