954,480 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

A problem with the C preprocessor.

Hello Daniweb,

I've ran against an issue in my code and i'm not sure why I receive an error. I've managed to reproduce the error with the following code:

#ifdef _WIN32
#define PERFORMANCE_METING
#endif

#ifdef PERFORMANCE_METING
#include <windows.h>
#endif

#include <stdio.h>
#include <stdlib.h>

typedef enum { FALSE, TRUE } Boolean;

int main()
{
    return 0;
}


This code gives me the following error for the line where the typedef is:

error: syntax error before numeric constant


Could anyone tell me why what I did is not allowed?
Besides that I was wondering if it was possible to check 2 symbols in 1 line with ifdef. (e.g. ifdef _WIN32 && PERFORMANCE_METING or something) or can I only use #if defined(_WIN32) && defined(PERFORMANCE_METING) for that?

Thanks in advance,

Gonbe.

-edit-
It doesn't seem to like include for some reason.
Do not know why though.

-edit-
Windef.h has a definition for FALSE and TRUE.. guess that's the issue.

Gonbe
Newbie Poster
14 posts since Jan 2010
Reputation Points: 10
Solved Threads: 2
 

>>This code gives me the following error for the line where the typedef is:

windows.h already defines TRUE and FALSE, which are #define's, not typedefs. I suppose you could undefine them before that typedef, but that could cause many other problems with win32 api functions.

>>or can I only use #if defined(_WIN32) && defined(PERFORMANCE_METING) for that?

Yes. But then you could have tried it yourself to find out.

Ancient Dragon
Retired & Loving It
Team Colleague
30,049 posts since Aug 2005
Reputation Points: 5,662
Solved Threads: 2,343
 

This article has been dead for over three months

Post: Markdown Syntax: Formatting Help
You