🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: comp.std.c++
Article #651

Re: Initialization of const dynamic objects

#651
From: John MAX Skaller
Date: Tue, 10 Nov 1992 01:28
51 lines
1969 bytes
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 ------------------
Technical Details
Message-ID: <1992Nov10.012803.29578@ucc.su.OZ.AU>
Path: arc1-ca.pugleaf.net!sparky!uunet!munnari.oz.au!metro!extro.ucc.su.OZ.AU!maxtal
References: <1deqlgINNmc0@darkstar.UCSC.EDU>

Show Full Headers
Complete Article Headers
Newsgroups: comp.std.c++
Path: arc1-ca.pugleaf.net!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