473,473 Members | 2,185 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

creation of static during destruction

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
5 1428
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
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

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
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

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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

5
by: Marijn | last post by:
I'd like to know how compilers usually handle static variables that are declared inside a function (as opposed to static class-members). Like in: int counter(){ static int c=0; ++c; return c;...
4
by: Gianni Mariani | last post by:
What does the standard say about this code ... #include <iostream> const char * func( const char * v ) { std::cout << "func called with v = " << v << "\n"; return v; }
3
by: John Ratliff | last post by:
When I dereference a pointer, does it make a copy of the object? Say I had a singleton, and wanted an static method to retrieve it from the class. class foo { private: static foo *bar; ...
1
by: Arnaud Debaene | last post by:
Hello, I think I found a bug in VC 7.1 concerning destruction of stack objects when linking a static, non managed, C++ library within a managed C++ application. Here is a repro case : 1)...
4
by: ma740988 | last post by:
Referencing source snippet below, the actual contruction of the foo objects is done in a class. In that regard, I chose methods, class1_construct and class2_construct for demonstration purposes....
55
by: Zytan | last post by:
I see that static is more restricted in C# than in C++. It appears usable only on classes and methods, and data members, but cannot be created within a method itself. Surely this is possible in...
14
by: Jeroen | last post by:
Hi all, I've got a question about writing a library. Let me characterize that library by the following: * there is a class A which is available to the user * there is a class B that is used...
5
by: cctv.star | last post by:
I need to maintain certain data structure, shared by all instances of a class, declared as . This data structure must change whenever a new object is created or an existing object is destroyed. So...
31
by: Tom P. | last post by:
I am doing quite a bit of custom painting and it means I have to create a lot of brushes (think one for every file system object in a directory) per paint. How expensive is this? Should I find a...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
1
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
1
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.