Topic: Temporaries have static storage duration?
Author: "Johannes Schaub (litb)" <schaub-johannes@web.de>
Date: Thu, 15 Oct 2009 22:15:38 CST Raw View
I wonder about 3.7.1[basic.stc.static]/1:
All objects which do not have dynamic storage duration, do not have thread
storage duration, and are not local have static storage duration. The
storage for these objects shall last for the duration of the program.
I always thought their storage duration is unspecified. Is the following
program valid, as a consequence of the above?
struct A {
int storage;
int *addy() { return &storage; }
};
int *get() { return A().addy(); }
int main() {
*get() = 42;
}
Notice that i'm not asking about its lifetime. I know that A() is destroyed
when the function returns. But since its storage is said to persist, we
should be able to reuse it, should we? Or is "A()" a "local object"? What
makes an object local? Thanks for all your insight.
--
[ comp.std.c++ is moderated. To submit articles, try just posting with ]
[ your news-reader. If that fails, use mailto:std-c++@netlab.cs.rpi.edu]
[ --- Please see the FAQ before posting. --- ]
[ FAQ: http://www.comeaucomputing.com/csc/faq.html ]
Author: tohava <tohava@gmail.com>
Date: Sun, 18 Oct 2009 08:53:51 CST Raw View
> I wonder about 3.7.1[basic.stc.static]/1:
>
> All objects which do not have dynamic storage duration, do not have thread
> storage duration, and are not local have static storage duration. The
> storage for these objects shall last for the duration of the program.
Aren't temporaries considered local in that respect?
--
[ comp.std.c++ is moderated. To submit articles, try just posting with ]
[ your news-reader. If that fails, use mailto:std-c++@netlab.cs.rpi.edu]
[ --- Please see the FAQ before posting. --- ]
[ FAQ: http://www.comeaucomputing.com/csc/faq.html ]
Author: "Johannes Schaub (litb)" <schaub-johannes@web.de>
Date: Sun, 18 Oct 2009 15:35:25 CST Raw View
tohava wrote:
>> I wonder about 3.7.1[basic.stc.static]/1:
>>
>> All objects which do not have dynamic storage duration, do not have
>> thread storage duration, and are not local have static storage duration.
>> The storage for these objects shall last for the duration of the program.
>
> Aren't temporaries considered local in that respect?
>
Temporaries are without a name, so they can't be inherited a scope. Even
though the Standard never defines the term "local object" (and there are
defect reports about that), i've always felt it means "an object defined by
a local name".
But now, of course if that's its meaning, this would have the consequence of
giving temporaries (except exception objects, i guess, which have been given
explicit license of having unspecified memory) static storage duration.
--
[ comp.std.c++ is moderated. To submit articles, try just posting with ]
[ your news-reader. If that fails, use mailto:std-c++@netlab.cs.rpi.edu]
[ --- Please see the FAQ before posting. --- ]
[ FAQ: http://www.comeaucomputing.com/csc/faq.html ]