18:47:46 Tuesday May 31 2005
image not found



Why can't people obey the standards? It isn't hard. No one has any respect for standards. As I shall demonstrate, unwashed open source hippies who talk a lot about respecting standards are as guilty as everyone else.

case 1:
Visual C++ does not understand scoping at all. Paste this into your compiler. Go on this will still be here when you return.

int x = 77;
for(int x=0; x<10; x++)
{}
printf("the value of x is %d\n", x);

What should the value of x be? It should be 77 because the x declared in the for loop only exists inside the for loop. Moreover there should be a warning about overriding a previous x. Does VC++ do either of these things? No.

case 2:
Both VC++ and gcc treat the result of the trinary conditional operator as an lvalue. If you check your copy of ISO 9899 section 6.5.15 you will find that it says EXPLICITLY that the conditional operator DOES NOT yield an lvalue. However feel free to try something like this. It is almost guaranteed to work on any given compiler:

int a=0, b=0;
(rand()%2) ? a : b = 42;

case 3:
gcc absolutely abuses the standard by allowing the second operand to the conditional operator to be omitted. Yep, try it out.

int alpha = 0;
int beta = 13;
alpha = (rand()%2) ? : beta;

This is exactly equivalent to:

alpha = (tmp=(rand()%2)) ? tmp : beta;

which, as it happens, is actually legal C.

case 4:
Today I discovered that Visual C++ disables certain language features by default. While attempting to use the dynamic_cast operator I discovered that RTTI was missing. This piece of information came to me by way of the mysterious compiler warning:

main.cpp(51): warning C4541: 'dynamic_cast' used on polymorphic type 'Foo' with /GR-; unpredictable behavior may result

What VC++ means to say is : "I am a crippled non-standard compiler. You need to explicitly enable RTTI by doing Project -> Properties -> C/C++ -> Language -> Enable Run-Time Type Info and then fiddling around with the drop box that will allow me to fully implement the C++ language."