Topic: storage duration of malloced objects (was reinterpret cast ...)
Author: clive@sco.com (Clive D.W. Feather)
Date: Mon, 11 Jul 1994 19:08:27 GMT Raw View
In article <1994Jul8.162050.12302@sal.wisc.edu>,
Alan Watson <alan@sal.wisc.edu> wrote:
> In article <CsM856.C6u@scone.london.sco.com>
> clive@sco.com (Clive D.W. Feather) wrote:
>> 6.1.2.4 *says* that there are
>> two lifetimes for objects, auto and static, and by implication that
>> there are none others.
> 6.1.2.4 does indeed enumerate only two storage durations -- `static'
> and `automatic'. However, it only defines the implications of those
> storage durations for objects with identifiers (in the first sentences
> of the second and third paragraphs). Heap objects have no identifiers,
> and so 6.1.2.4 leaves undefined their actual storage duration and the
> implications of that storage duration.
The second paragraph is:
|| An object whose identifier is declared with external or internal linkage,
|| or with the storage-class specifier static has static storage duration.
|| For such an object, storage is reserved and its stored value is
|| initialized only once, prior to program startup. The object exists and
|| retains its last-stored value throughout the execution of the entire
|| program.
[The third paragraph has the same format but is longer.]
I read this as saying two things:
* An object declared thus has static storage duration. It does *not* say
that *only* these objects have static storage duration. There exist
objects, such as those defined by the system library, which are not
declared in this way and yet which have static storage duration.
* Objects with static storage duration have certain properties.
That leaves the storage duration of heap objects undefined; a Defect
Report is being submitted.
--
Clive D.W. Feather | Santa Cruz Operation | If you lie to the compiler,
clive@sco.com | Croxley Centre | it will get its revenge.
Phone: +44 923 816 344 | Hatters Lane, Watford | - Henry Spencer
Fax: +44 923 210 352 | WD1 8YN, United Kingdom |
Author: t_akrishnan@bart.hns.com (Ajoy KT)
Date: Fri, 8 Jul 1994 01:48:00 GMT Raw View
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)*/
Author: clive@sco.com (Clive D.W. Feather)
Date: Fri, 8 Jul 1994 09:39:05 GMT Raw View
In article <7JUL199421482411@lando.hns.com>,
Ajoy KT <t_akrishnan@bart.hns.com> wrote:
> 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.
6.1.2.4 to 6.1.2.6 talk about concepts which are mostly related to
identifiers, hence the grouping into 6.1.2, but not entirely. There is
*no* statement of the form "The contents of 6.1.2 apply only to
identifiers".
> 6.1.2.4 defines the lifetimes of auto and static objects;
That's putting the cart before the horse. 6.1.2.4 *says* that there are
two lifetimes for objects, auto and static, and by implication that
there are none others.
[A proposed response to a Defect Report currently in the system says
that "there are four signed integer types" [6.1.2.5] can *not* be treated
as "there are four or more signed integer types".]
--
Clive D.W. Feather | Santa Cruz Operation | If you lie to the compiler,
clive@sco.com | Croxley Centre | it will get its revenge.
Phone: +44 923 816 344 | Hatters Lane, Watford | - Henry Spencer
Fax: +44 923 210 352 | WD1 8YN, United Kingdom |
Author: alan@sal.wisc.edu (Alan Watson)
Date: Fri, 8 Jul 1994 16:20:50 GMT Raw View
In article <CsM856.C6u@scone.london.sco.com>
clive@sco.com (Clive D.W. Feather) wrote:
>6.1.2.4 *says* that there are
>two lifetimes for objects, auto and static, and by implication that
>there are none others.
6.1.2.4 does indeed enumerate only two storage durations -- `static'
and `automatic'. However, it only defines the implications of those
storage durations for objects with identifiers (in the first sentences
of the second and third paragraphs). Heap objects have no identifiers,
and so 6.1.2.4 leaves undefined their actual storage duration and the
implications of that storage duration. 7.10.3 does not resolve the
ambiguity of the name of the storage duration, but does resolve the
semantics.
[I will, of course, deny vigorously that I wrote any of the above.]
--
Alan Watson | To be sure, there are certain penitential
alan@oldp.astro.wisc.edu | exercises to be performed -- the
Department of Astronomy | presentation of a paper, perhaps, and
University of Wisconsin -- Madison | certainly listening to the papers of
| others. -- David Lodge on conferences