473,503 Members | 5,593 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

surprised that this is valid...

Hi all,

I've per chance noticed that this code compiles without warnings:

struct x
{
x(): y_( y_ ){}

int y_;
};

I've used gcc 4.1.0, comeau online and all compilers available at
dinkumware online.

Are there cases where similar code (a member initialising itself with
itself) would make sense? I was surprised when I discovered this.

Regards,

Werner
Mar 18 '08 #1
2 1241
On Mar 18, 11:14*am, "jason.cipri...@gmail.com"
<jason.cipri...@gmail.comwrote:
Note that if there is an x or a y (or in your case a y_) in a larger
scope, then it will use the larger scoped one instead:

int x = 0, y = 0;

void function () {
* int x(x); // now it uses x from above
* int y = y; // same here

}
No, both x and y are still being initialized with their own
indeterminate values - the x and y declarations in the outer scope
make no difference here. In short, the inner x and y declarations hide
the outer ones.

There is one notable exception, however:

const int i = 2;
{
int i[i];
}

In this case, the inner "i" declares an array of two ints.

Greg

Mar 18 '08 #2
On Mar 18, 6:26 pm, Greg Herlihy <gre...@mac.comwrote:
On Mar 18, 11:14 am, "jason.cipri...@gmail.com"

<jason.cipri...@gmail.comwrote:
Note that if there is an x or a y (or in your case a y_) in a larger
scope, then it will use the larger scoped one instead:
int x = 0, y = 0;
void function () {
int x(x); // now it uses x from above
int y = y; // same here
}

No, both x and y are still being initialized with their own
indeterminate values - the x and y declarations in the outer scope
make no difference here. In short, the inner x and y declarations hide
the outer ones.
Oops, thanks for catching that, Greg.
There is one notable exception, however:

const int i = 2;
{
int i[i];
}

In this case, the inner "i" declares an array of two ints.

Greg
Mar 18 '08 #3

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

Similar topics

16
8079
by: siliconmike | last post by:
Hi, I'm looking for a reliable script that would connect to a host and somehow determine whether an email address is valid. since getmxrr() only gets the mx records.. Links/pointers ? Mike
5
1891
by: NNTP | last post by:
#!/usr/bin/perl use Validate::Net; if ( Validate::Net->ip($ARGV)) { print "valid"; exit 0; } print "invalid"; #--done
0
1557
by: djake | last post by:
This have surprised me in discovering that all relative path in a html page don't work when included in an VC++ MFC project with DHTML support (class CDHtmlDialog). So I've tryed to include...
0
623
by: QA | last post by:
I am using a Business Scorecard Accelarator in a Sharepoint Portal 2003 using SQL Server 2005 I am getting the following error: Error,5/7/2005 10:50:14 AM,580,AUE1\Administrator,"Specified cast is...
6
4841
by: scottyman | last post by:
I can't make this script work properly. I've gone as far as I can with it and the rest is out of my ability. I can do some html editing but I'm lost in the Java world. The script at the bottom of...
9
5671
by: David Thielen | last post by:
Hi; What's the fastest way to verify that an xml file is well-formed (and valid if it has a dtd)? I don't want to pull any data out, I just want to make sure it is a good file. (When the user...
1
2438
by: illegal.prime | last post by:
Hey all, I have an app, that could take two numbers of any type of numerical type int, long, double, float, uint, ulong, etc. I want to check that the numbers are part of a range that I consider...
2
2166
by: Arpan | last post by:
I came across the following statement at http://windowssdk.msdn.microsoft.com/en-us/library/hdf992b8.aspx: Although an XML document is considered to be well formed if it meets all the...
13
8440
by: Edje.Rommel | last post by:
Hello, I've have a problem with a webservice. I just want to validate a VAT number by country code and VAT numer. The return value should be like "it's valid" and/or the name where it's...
0
7188
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
7063
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
7258
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
1
6970
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
5558
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
4987
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
4663
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
3146
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
1489
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 ...

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.