Standard conformant C++

A place for Ogre users to discuss non-Ogre subjects with friends from the community.
Post Reply
Bekas
OGRE Expert User
OGRE Expert User
Posts: 253
Joined: Sat Oct 16, 2004 11:21 pm
x 1

Standard conformant C++

Post by Bekas »

What compiler do you think is more standard conformant, GCC or VC++ ?

Wait! Don't answer that. Not before considering this:
C++ 6.4p1 (selection-statements):
selection-statement:
if ( condition ) statement
if ( condition ) statement else statement
switch ( condition ) statement

C++ 6.4p2:
The rules for conditions apply both to selection-statements and to the for and while statements

C++ 6.4p3:
A name introduced by a declaration in a condition is in scope from its point of declaration until the end of the substatements controlled by the condition. If the name is re-declared in the outermost block of a substatement controlled by the condition, the declaration that re-declares the name is ill-formed.
Example:

Code: Select all

if (int x = f()) {
  int x; // ill-formed, redeclaration of x
}
else {
  int x; // ill-formed, redeclaration of x
}
if/switch/while/for statements, that's pretty common stuff, no weird templated code involved. Both compilers should be able to handle them as stated, right ?
Let's see...

VC++

Code: Select all

int f();
void g() {
  if (int x=f()) {
    int x; // error, PASS
  }
  switch (int x=f()) {
    default:
      int x; // no error, FAIL
  }
  while (int x=f()) {
    int x; // error, PASS
  }
  for (;int x=f();) {
    int x; // error, PASS
  }
}
3 PASS, 1 FAIL

GCC

Code: Select all

int f();
void g() {
  if (int x=f()) {
    int x; // no error, FAIL
  }
  switch (int x=f()) {
    default:
      int x; // no error, FAIL
  }
  while (int x=f()) {
    int x; // error, PASS
  }
  for (;int x=f();) {
    int x; // error, PASS
  }
}
2 PASS, 2 FAIL

And there's more...
C++ 6.5.3p1 (The for statement)
The for statement:
for ( for-init-statement condition[optinal] ; expression[optional] ) statement

Names declared in the for-init-statement are in the same declarative-region as those declared in the condition.
Let's do some tests..

VC++

Code: Select all

int f();
void g() {
  for (int x; int x=f();) {} // redeclaration error, PASS
}
GCC

Code: Select all

int f();
void g() {
  for (int x; int x=f();) {} // no error, FAIL
}
Ok, what are the results?

VC++: 4 PASS, 1 FAIL
GCC: 2 PASS, 3 FAIL

And the round goes to.. VC++ :)
MOGRE (Managed OGRE) - Advanced .NET wrapper for Ogre
User avatar
nullsquared
Old One
Posts: 3245
Joined: Tue Apr 24, 2007 8:23 pm
Location: NY, NY, USA
x 11

Post by nullsquared »

My personal favorite is that VC++ allows references to temporaries, which is illegal.

Both compilers have their quirks, and if you work out all of these quirks (not just a select few), VC++ is the less C++ standard compliant one.
User avatar
PolyVox
OGRE Contributor
OGRE Contributor
Posts: 1316
Joined: Tue Nov 21, 2006 11:28 am
Location: Groningen, The Netherlands
x 18
Contact:

Post by PolyVox »

I've heard particularly good things about the Digital Mars C++ compiler. I believe it's the only one which supports the (standard!) 'export' keyword.
Post Reply