473,385 Members | 1,907 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,385 software developers and data experts.

A compiler difference & the C++ standard

Came across a strange compiler difference today and wasn't sure which
compiler had the bug.

void AFunction( Rect &aRect )
{
if ( 1 ) {
Rect aRect = { aRect.top, aRect.left, aRect.bottom, aRect.right };
}
}

Now, granted, this is a very weird way to write things (I didn't write
code this way :-), but Microsoft Visual C++, aRect.top apparently
refers
to the aRect parameter that was passed into the function.

X-Code (which uses gcc as it's compiler) has aRect.top referring to
the aRect declared within the scope of
the if statement.

So, what does the C++ standard say?

Mar 28 '07 #1
2 1324
On Mar 28, 4:33 pm, "Eric" <ericg...@gmail.comwrote:
Came across a strange compiler difference today and wasn't sure which
compiler had the bug.

void AFunction( Rect &aRect )
{
if ( 1 ) {
Rect aRect = { aRect.top, aRect.left, aRect.bottom, aRect.right };
}

}

Now, granted, this is a very weird way to write things (I didn't write
code this way :-), but Microsoft Visual C++, aRect.top apparently
refers
to the aRect parameter that was passed into the function.

X-Code (which uses gcc as it's compiler) has aRect.top referring to
the aRect declared within the scope of
the if statement.

So, what does the C++ standard say?
gcc is right. IIRC, Stroustrup says it is "silly and perverse, but
not illegal" for an identifier to be used as its own initialiser.

- Anand

Mar 28 '07 #2
Dnia Wed, 28 Mar 2007 14:33:16 -0700, Eric napisał(a):
void AFunction( Rect &aRect )
{
if ( 1 ) {
Rect aRect = { aRect.top, aRect.left, aRect.bottom, aRect.right };
}
}
So, what does the C++ standard say?
Declared identifier name is known from the place his declarator ends
[before the '=' sign in the declaration, if any]. So, in the code:

Rect aRect = { aRect.top, aRect.left, aRect.bottom, aRect.right };
|
'-------------------------.
the second aRect is known from here --' and starts to hide the
first aRect name [being the parameter of AFunction].
The reason was that the following should be possible and valid:

int x = x;

thus it is in most cases stupid ;)

--
SasQ
Mar 29 '07 #3

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

Similar topics

13
by: Mattias Campe | last post by:
Hi, Depending on if I get an image or a text of a certain URL, I want to do something different. I don't know in advance whether I'll get an image or a text. This is a URL that returns an...
11
by: Chris Mantoulidis | last post by:
Out of curiosity, I wanted to test executable file sizes of the same program from different compilers... The 2 compilers I tested (both old, on purpose) were Borland C++ 3.1 and DJGPP 2.03... ...
2
by: Kenneth Gomez | last post by:
Hello, I have tried many avenues (web search, borland website, libxml website) before deciding to post here. I'm trying to install libxml2 on windows ME to work with my Borland C++ 5 Compiler...
233
by: E. Robert Tisdale | last post by:
I have access to a wide variety of different platforms here at JPL and they all have pretty good C 99 compilers. Some people claim that they have not moved to the new standard because of the...
8
by: Charles Sullivan | last post by:
I have a program written in C under Linux (gcc) which a user has ported to run under AT&T SysV R4. He sent me a copy of his makelog which displays a large number of compiler warnings similar to...
6
by: toton | last post by:
Hi, Anyone have a link to comparative study of different C++ compilers and how much they conform to C++ language standard? Most of the big platforms I know have GCC which well supports C++...
43
by: JohnQ | last post by:
Are a default constructor, destructor, copy constructor and assignment operator generated by the compiler for a struct if they are not explicitely defined? I think the answer is yes, because...
41
by: Miroslaw Makowiecki | last post by:
Where can I download Comeau compiler as a trial version? Thanks in advice.
4
by: dan | last post by:
I am trying to port a legacy MFC application to C++/CLI. I have managed to build the code under VS 2008 and I am in the process of enabling the /CLR compiler directive. My goal is to try and...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
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
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,...

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.