home *** CD-ROM | disk | FTP | other *** search
- Newsgroups: comp.std.c++
- Path: sparky!uunet!munnari.oz.au!metro!extro.ucc.su.OZ.AU!maxtal
- From: maxtal@extro.ucc.su.OZ.AU (John MAX Skaller)
- Subject: Re: Initialization of const dynamic objects
- Message-ID: <1992Nov10.012803.29578@ucc.su.OZ.AU>
- Sender: news@ucc.su.OZ.AU
- Nntp-Posting-Host: extro.ucc.su.oz.au
- Organization: MAXTAL P/L C/- University Computing Centre, Sydney
- References: <1deqlgINNmc0@darkstar.UCSC.EDU>
- Date: Tue, 10 Nov 1992 01:28:03 GMT
- Lines: 51
-
- In article <1deqlgINNmc0@darkstar.UCSC.EDU> daniel@cse.ucsc.edu (Daniel R. Edelson) writes:
- >
- >Section 7.1.6 contains the following statement:
- >
- > ``Unless explicitly declared extern, a const
- > object does not have external linkage and
- > must be initialized.''
- >
- >Does that prohibit the following code?
- >
- > new const int;
- >
- >This allocates an uninitialized const object.
-
- IMHO there is no such thing as a const *object*. 'const' controls
- the access to an object, const T and T are the same type (this not
- how the ARM is written though).
-
- However,
-
- const int *p=new int;
-
- makes p a pointer with const access to an undefined int. This is just like
-
- int x; // no init
- const int *p=&x;
-
- >Seems like this should be explicitly prohibited (assuming
- >there's no constructor, of course.) Is it?
- >
- >Incidently, section 5.3.3 says:
- >
- > ``If [a new-initializer is] not [present], the object
- > will start out with an unspecified value.''
- >
- >Thus, an unitialized const dynamic object has and keeps
- >forever an unspecified value. This should be prohibited.
-
- Not necessarily. With p as above
-
- *(int*)p=5; // p now points to 5, we can cast away const :-(
-
- And of course
-
- x=5;
-
- --
- ;----------------------------------------------------------------------
- JOHN (MAX) SKALLER, maxtal@extro.ucc.su.oz.au
- Maxtal Pty Ltd, 6 MacKay St ASHFIELD, NSW 2131, AUSTRALIA
- ;--------------- SCIENTIFIC AND ENGINEERING SOFTWARE ------------------
-