Tran said:
Hi,
I am new to C++. Could someone explain the meaning of below code:
# pragma warning(disable : 4786)
# define for if(0){}else for
Thanks
Tran Hong Quang
1. Look up C4786 in the help to see what this warning relates to. This
warning often comes up when using the standard library, because expanded
identifiers can easily have more than 255 characters. You might as well
always turn this warning off, because not much can be done about it.
2. I think this is a trick for preventing the identifier i being
injected into the surrounding scope when you write, for example
for (int i=0; i<10; i++)
{
}
Some versions of VC do not adhere to the C++ standard, which says that i
should be local to the scope of the loop. This allows you to write
for (int i=0; i<10; i++)
{
}
for (int i=0; i<10; i++)
{
}
without getting error that i is multiply defined. Personally, this hack
makes me nervous and I tend to do
int i;
for (i=0; i<10; i++)
{
}
for (i=0; i<10; i++)
{
}
HTH,
David Wilkinson