From -5035769899015592760
X-Google-Language: ENGLISH,ASCII-7-bit
X-Google-Thread: 1149ec,a050958d123ab616,start
X-Google-Attributes: gid1149ec,public
X-Google-Thread: f78e5,a050958d123ab616,start
X-Google-Attributes: gidf78e5,public
X-Google-ArrivalTime: 1994-07-08 01:21:13 PST
Newsgroups: comp.std.c,comp.std.c++
Path: bga.com!news.sprintlink.net!hookup!usc!sdd.hp.com!sgiblab!wetware!spunky.RedBrick.COM!psinntp!hns!lando.hns.com!aurora
From: t_akrishnan@bart.hns.com (Ajoy KT)
Subject: Re: storage duration of malloced objects (was Re: reinterpret cast ...)
Message-ID: <7JUL199421482411@lando.hns.com>
Sender: aurora@lando.hns.com (CONTI, DENNIS)
Date: Fri, 8 Jul 1994 01:48:00 GMT
News-Software: VAX/VMS VNEWS 1.41    
Organization: Hughes Network Systems, Inc.
Lines: 56
Xref: bga.com comp.std.c:1880 comp.std.c++:3185

Subject: Re: reinterpret cast int* to unsigned* (was: Re: Mutable references?)
In <CsHHqM.G2z@ucc.su.OZ.AU> maxtal@physics.su.OZ.AU (John Max Skaller) writes
>In article <CsGzp3.1wA@crdnns.crd.ge.com> volpe@ausable.crd.ge.com writes:
>>>	I'm sorry that you do not understand my explanation
>>>of the problem.   Please try.
>>>	void f() {
>>>		int *pi = malloc(sizeof(int));
>>>		*pi = 1;
>>>		printf("%d", *pi);
>>>	}

>>>Nothing in the C Standard promises that the output will be "1".
>>>As far as I know. Please point out the words that contradict
>>>this assertion if you can, thus educating me.

>>The entire standard, taken as a whole, promises this. 
>>"*pi" is an int.

>	So what. *pi exists only when the expression it contains
>is executed. After that, no object exists. So there is no
>object which persists to retain the value 1.

	[Clive Feather, in a later post, points out that section 6.1.2.4
does not mention objects with heap storage duration; and promises a DR].

	ISO C Section 6.1.2.4 (on which presumably the argument that no object
exists for malloced memory, is based) talks *only* of objects associated
with *identifiers*. Section 6.1.2 (which, obviously is the enclosing section
for 6.1.2.4) has the title "Identifiers" - hence 6.1.2.4 is talking of
objects defined with identifiers. Hence I think Clive Feather's assertion
is rather out of context.

	Section 7.10.3 (Memory management functions) is the place to look
for to find out the storage duration of malloc-ed objects. And there, the
standard states that the allocated space can be accessed till an explicit
free or realloc takes place.

>	Auto and static objects persist. The C Standard defines
>their lifetimes and it DENIES EXPLICITLY the existence
>of other objects.

	6.1.2.4 defines the lifetimes of auto and static objects; 7.10.3
defines the lifetime of malloced objects. The only omission is that
7.10.3 does not talk about retention of last-stored values. However, since
the very definition of an object says that it is a region of data *storage*,
it is quite possible to conclude that all objects retain their last-stored
values as long as they are live. 
	
-----
/* "Words mean ...." - an Humpty-Dumpty unquotable quote */

/* Ajoy Krishnan T,
   Senior Software Engineer, Hughes Software Systems,
   New Delhi - 19, India.
   (ajoyk%hss@lando.hns.com)*/



