473,408 Members | 2,417 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,408 software developers and data experts.

does value-initialization happen for global and local static object ?

Suppose I have

#include <cstdlib>
#include <iostream>

using namespace std;

class Test
{
public:
int i;
double d;
char* str;
};

Test obj;

int main()
{
static Test one;
return EXIT_SUCCESS;
}

Will the global 'Test obj' and the local static 'Test one' be value-
initialized ?
What does the C++ standard say in this regard ?

Kindly clarify.

Thanks
V.Subramanian
Jun 27 '08 #1
4 1674
* su**************@yahoo.com, India:
Suppose I have

#include <cstdlib>
#include <iostream>

using namespace std;

class Test
{
public:
int i;
double d;
char* str;
};

Test obj;

int main()
{
static Test one;
return EXIT_SUCCESS;
}

Will the global 'Test obj' and the local static 'Test one' be value-
initialized ?
What does the C++ standard say in this regard ?
They're zero-initialized.

This happens before any dynamic initialization.
Cheers, & hth.,

- Alf
Jun 27 '08 #2
On Apr 20, 1:43 am, "Alf P. Steinbach" <al...@start.nowrote:
* subramanian10...@yahoo.com, India:

They're zero-initialized.

This happens before any dynamic initialization.

Cheers, & hth.,

- Alf
Is zero-initialization different from value_initialization ?

What is meant by dynamic initialization ?

Kindly explain ?

Thanks
V.Subramanian
Jun 27 '08 #3
* su**************@yahoo.com, India:
On Apr 20, 1:43 am, "Alf P. Steinbach" <al...@start.nowrote:
>* subramanian10...@yahoo.com, India:

They're zero-initialized.

This happens before any dynamic initialization.

Cheers, & hth.,

- Alf

Is zero-initialization different from value_initialization ?
In the general case, yes. Value initialization reduces to zero initialization
for POD (Plain Old Data) types.

What is meant by dynamic initialization ?
Initialization that requires function calls, e.g. of constructors.
Cheers, & hth.,

- Alf
Jun 27 '08 #4
On Apr 20, 11:25 pm, "Alf P. Steinbach" <al...@start.nowrote:
* subramanian10...@yahoo.com, India:
On Apr 20, 1:43 am, "Alf P. Steinbach" <al...@start.nowrote:
* subramanian10...@yahoo.com, India:
Is zero-initialization different from value_initialization ?

In the general case, yes. Value initialization reduces to zero initialization
for POD (Plain Old Data) types.
Please give me an example where zero-initialization is different from
value_initialization.

By value-initialization, I understand that all arithmetic type data
members will be set to zero, the pointer type data members will be set
to null pointer and for class type data object members, the
corresponding default ctor, if present, will be called(if default ctor
for the member object is not present, then the above process goes
recursively.)

Is my understanding correct ?

Kindly explain.

Thanks
V.Subramanian
Jun 27 '08 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

14
by: billy.becker | last post by:
I need to save a wav file that is HTTP POSTed to a php page. What does PHP5 do automatically to a POSTed variable when it puts it in the $_POST superglobal array? I haven't been able to find any...
37
by: Curt | last post by:
If this is the complete program (ie, the address of the const is never taken, only its value used) is it likely the compiler will allocate ram for constantA or constantB? Or simply substitute the...
11
by: Saqib Ali | last post by:
Please excuse me, this is a fairly involved question that will likely require you to save the file below to a file and open it in a browser. I use Mozilla 1.5, so the problem I describe below...
4
by: Anon Email | last post by:
Hi people, Another question. In the code below, why is there a screen output? This part of the code: bool status = TheCalculator.Execute(input); is merely assigning the result of the...
15
by: greenflame | last post by:
First of all I only have IE for testing. Ok. I have a script that is supposed to show, not evaluate, the indefinite integral of something. When I run the script it just craches IE. I have tried...
8
by: McKirahan | last post by:
Firefox does not reflect selected option via innerHTML How do I get Firefox to reflect selected option values? <html> <head> <title>FFinner.htm</title> <script type="text/javascript">...
9
by: Stan B | last post by:
I create a popup window by calling window.showModalDialog Popup window has Ok button with this code attached: === string Script = "<script language=JavaScript>" + "{" + "window.close();" +...
130
by: Daniel Manes | last post by:
I'm baffled. I have a column in a SQL Server Express database called "Longitude," which is a float. When I view the table in a DataGridView, some of the numbers, which only have two decimal places...
7
by: prash.marne | last post by:
Hello, I have a simple form <form method="POST"> <select name="activity"> <option value="0">None</option> <option value="M" onclick="popup_onclick()">Select Multiple</option> <option...
2
by: haft | last post by:
My webpage of discussion contains a javascript powered image gallery of small thumbnail images that when moused-over, display a larger image that corresponds to the current moused-over thumbnail....
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
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...
0
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
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...

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.