473,809 Members | 2,703 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 1704
* 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.no wrote:
* subramanian10.. .@yahoo.com, India:

They're zero-initialized.

This happens before any dynamic initialization.

Cheers, & hth.,

- Alf
Is zero-initialization different from value_initializ ation ?

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.no wrote:
>* subramanian10.. .@yahoo.com, India:

They're zero-initialized.

This happens before any dynamic initialization.

Cheers, & hth.,

- Alf

Is zero-initialization different from value_initializ ation ?
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.no wrote:
* subramanian10.. .@yahoo.com, India:
On Apr 20, 1:43 am, "Alf P. Steinbach" <al...@start.no wrote:
* subramanian10.. .@yahoo.com, India:
Is zero-initialization different from value_initializ ation ?

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_initializ ation.

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
4340
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 info on this.... I have a script that does what I want in PERL, but I need to do it in PHP. I think the PERL does something magic when it does this:
37
4700
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 values in (as would be required if I used the hideous, evil, much-abused #define :) ----------- const int constantA = 10; static const int constantB = 20;
11
2033
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 should be reproducible with that version at least. BACKGROUND: =========== When you open this page in your browser, you will see a 4 cell table. The cells contain the following items respectively:
4
2101
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 function call to status. In fact, I don't understand why I am allowed to perform this assignment at all, since the Execute method contains more than just a boolean
15
2159
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 to get all the obvious bugs out... Um... The script is at: http://ali.freezope.org/idf test and what it is supposed to show is at: http://ali.freezope.org/idf result
8
8452
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"> function clicks() { document.getElementById("t1").value =
9
4662
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();" + "}" + "</script>";
130
6651
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 in the database show up with *15* decimal places and are ever so slightly off (in the example in the subject line, by about 2E-15). I'm not doing any operations on this column. It's just running a stored procedure which performs a pretty basic...
7
33693
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 value="1">Kayaking</option>
2
1490
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. An image caption (whose value is populated by my alt_img database field), also changes according to the current moused-over thumbnail image. All functions fine...except...for the initial value for the alt_jmg database field. The caption text for...
0
9601
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10376
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10379
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9199
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7660
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6881
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 then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5550
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 last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
4332
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
3
3014
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.