What exactly is the compiler thinking?

  • Thread starter Thread starter Vinayak Raghuvamshi
  • Start date Start date
V

Vinayak Raghuvamshi

Visual Studio .Net 2003 Enterprise Architect. (VC++ code)

a developer in our team made a typo and his code looks like this

if (sendMessage == NULL)
m_ErrorCode = 0 ERR_MESSAGE_EMPTY;

But the compiler did not crib at all ! everything built fine....

is this a .Net compiler thing or is it some whacky C++ standard that
we are not aware of? (we do not know of any standards that specify the
occurence of a space char as anything other than a space char).

-Vinayak
 
Vinayak said:
Visual Studio .Net 2003 Enterprise Architect. (VC++ code)

a developer in our team made a typo and his code looks like this

if (sendMessage == NULL)
m_ErrorCode = 0 ERR_MESSAGE_EMPTY;

But the compiler did not crib at all ! everything built fine....

is this a .Net compiler thing or is it some whacky C++ standard that
we are not aware of? (we do not know of any standards that specify the
occurence of a space char as anything other than a space char).

-Vinayak

What's the definition of ERR_MESSAGE_EMPTY? If it's a macro, you can compile
with /P and view the .i file that is produced to see the result of
preprocessing.
 
Visual Studio .Net 2003 Enterprise Architect. (VC++ code)

a developer in our team made a typo and his code looks like this

if (sendMessage == NULL)
m_ErrorCode = 0 ERR_MESSAGE_EMPTY;

But the compiler did not crib at all ! everything built fine....

is this a .Net compiler thing or is it some whacky C++ standard that
we are not aware of? (we do not know of any standards that specify the
occurence of a space char as anything other than a space char).

What is the definition of ERR_MESSAGE_EMPTY? If it's

#define ERR_MESSAGE_EMPTY +0

then I don't see the problem. We need a short and complete repro case
or it's a bit hard to comment...

Tom
 
If say ERR_MESSAGE_EMPTY is defined as
#define ERR_MESSAGE_EMPTY 12
then the compiler would have cribed as
error C2143: syntax error : missing ';' before 'constant'

but if ERR_MESSAGE_EMPTY is defined as any expression like
#define ERR_MESSAGE_EMPTY +12
or simply
#define ERR_MESSAGE_EMPTY

Then the meaning of that line would become
either m_ErrorCode = 0 +12; or m_ErrorCode = 0;

which is just fine. Either use /P to get the preprocessed file to see what
the expression is resulting into or go to
Project->properties->Preprocessor->Generate Preprocessed file (which inserts
/P is you compiler option)
 
Doug Harrison said:
What's the definition of ERR_MESSAGE_EMPTY? If it's a macro, you can compile
with /P and view the .i file that is produced to see the result of
preprocessing.

Sorry, My Bad. ERR_MESSAGE_EMPTY was defined as -17 :-(

I am already feeling very stupid and feel like eating my shoe...

thanks for the response, though.

-Vinayak
 
Vinayak said:
Sorry, My Bad. ERR_MESSAGE_EMPTY was defined as -17 :-(

To fix the problem and avoid it in the future, you can enclose it in
parentheses or change it from a macro to a const int.
 
Back
Top