By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
454,112 Members | 1,019 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 454,112 IT Pros & Developers. It's quick & easy.

creation of static during destruction

P: n/a
hey all

class A
{

};
class B
{
~B()
{
static A a;
}
};

static B b;

Is this undefined behavior. or the standard seems to handle this case
as well ?

Thanks
Raja

Dec 21 '06 #1
Share this Question
Share on Google+
5 Replies


P: n/a
Parapura Rajkumar wrote:
hey all

class A
{

};
class B
{
~B()
{
static A a;
}
};

static B b;

Is this undefined behavior.
No. It's an error. B cannot be instantiated.

Dec 21 '06 #2

P: n/a
Parapura Rajkumar wrote:
class A
{

};
class B
{
~B()
{
static A a;
}
};

static B b;

Is this undefined behavior. or the standard seems to handle this case
as well ?
I think it's unspecified.

The Standard (as I read it) says that the destruction of 'a' will
happen before B::~B returns (since it was constructed after 'b',
it has to be destroyed completely before 'b' is), however, it is known
that calling d-tors for static objects is done by registering them
with 'atexit' (although it is not explicitly specified by the Standard),
and the Standard does not specify what happens if you [try to] register
a function with 'atexit' while another function previously registered
with 'atexit' is executed during the program termination.

You might want to ask about it in comp.std.c++, refer to 3.6.3, 18.3,
6.7.

I say, try to avoid situations like that if possible.

V
--
Please remove capital 'A's when replying by e-mail
I do not respond to top-posted replies, please don't ask
Dec 21 '06 #3

P: n/a

Rolf Magnus wrote:
Parapura Rajkumar wrote:
hey all

class A
{

};
class B
{
~B()
{
static A a;
}
};

static B b;

Is this undefined behavior.

No. It's an error. B cannot be instantiated.
Why is that.. i omitted the public to keep the post terse

Dec 21 '06 #4

P: n/a
Rolf Magnus wrote:
Parapura Rajkumar wrote:
>hey all

class A
{

};
class B
{
~B()
{
static A a;
}
};

static B b;

Is this undefined behavior.

No. It's an error. B cannot be instantiated.
Oh, come on!
Dec 21 '06 #5

P: n/a

Parapura Rajkumar wrote:
hey all

class A
{

};
class B
{
~B()
{
static A a;
}
};

static B b;

Is this undefined behavior. or the standard seems to handle this case
as well ?

Thanks
Raja

what is the use of this......B destructor will be called when B process
is complete...

Dec 22 '06 #6

This discussion thread is closed

Replies have been disabled for this discussion.