home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #26 / NN_1992_26.iso / spool / comp / std / cplus / 1525 < prev    next >
Encoding:
Text File  |  1992-11-09  |  1.9 KB  |  64 lines

  1. Newsgroups: comp.std.c++
  2. Path: sparky!uunet!munnari.oz.au!metro!extro.ucc.su.OZ.AU!maxtal
  3. From: maxtal@extro.ucc.su.OZ.AU (John MAX Skaller)
  4. Subject: Re: Initialization of const dynamic objects
  5. Message-ID: <1992Nov10.012803.29578@ucc.su.OZ.AU>
  6. Sender: news@ucc.su.OZ.AU
  7. Nntp-Posting-Host: extro.ucc.su.oz.au
  8. Organization: MAXTAL P/L C/- University Computing Centre, Sydney
  9. References: <1deqlgINNmc0@darkstar.UCSC.EDU>
  10. Date: Tue, 10 Nov 1992 01:28:03 GMT
  11. Lines: 51
  12.  
  13. In article <1deqlgINNmc0@darkstar.UCSC.EDU> daniel@cse.ucsc.edu (Daniel R. Edelson) writes:
  14. >
  15. >Section 7.1.6 contains the following statement:
  16. >
  17. >    ``Unless explicitly declared extern, a const
  18. >    object does not have external linkage and
  19. >    must be initialized.''
  20. >
  21. >Does that prohibit the following code?
  22. >
  23. >    new const int;
  24. >
  25. >This allocates an uninitialized const object. 
  26.  
  27.     IMHO there is no such thing as a const *object*. 'const' controls
  28. the access to an object, const T and T are the same type (this not
  29. how the ARM is written though).
  30.  
  31.     However,
  32.  
  33.     const int *p=new int;
  34.  
  35. makes p a pointer with const access to an undefined int. This is just like
  36.  
  37.     int x; // no init
  38.     const int *p=&x;
  39.  
  40. >Seems like this should be explicitly prohibited (assuming
  41. >there's no constructor, of course.) Is it?
  42. >
  43. >Incidently, section 5.3.3 says:
  44. >
  45. >    ``If [a new-initializer is] not [present], the object
  46. >    will start out with an unspecified value.''
  47. >
  48. >Thus, an unitialized const dynamic object has and keeps
  49. >forever an unspecified value. This should be prohibited.
  50.  
  51.     Not necessarily. With p as above 
  52.  
  53.     *(int*)p=5; // p now points to 5, we can cast away const :-(
  54.  
  55.     And of course 
  56.  
  57.     x=5;
  58.  
  59. -- 
  60. ;----------------------------------------------------------------------
  61.         JOHN (MAX) SKALLER,         maxtal@extro.ucc.su.oz.au
  62.     Maxtal Pty Ltd, 6 MacKay St ASHFIELD, NSW 2131, AUSTRALIA
  63. ;--------------- SCIENTIFIC AND ENGINEERING SOFTWARE ------------------
  64.