943,147 Members | Top Members by Rank

Ad:
  • C Discussion Thread
  • Unsolved
  • Views: 480
  • C RSS
Feb 24th, 2010
0

A problem with the C preprocessor.

Expand Post »
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:

  1. #ifdef _WIN32
  2. #define PERFORMANCE_METING
  3. #endif
  4.  
  5. #ifdef PERFORMANCE_METING
  6. #include <windows.h>
  7. #endif
  8.  
  9. #include <stdio.h>
  10. #include <stdlib.h>
  11.  
  12. typedef enum { FALSE, TRUE } Boolean;
  13.  
  14. int main()
  15. {
  16. return 0;
  17. }

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

  1. 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 <windows.h> for some reason.
Do not know why though.

-edit-
Windef.h has a definition for FALSE and TRUE.. guess that's the issue.
Last edited by Gonbe; Feb 24th, 2010 at 1:56 pm.
Similar Threads
Reputation Points: 10
Solved Threads: 2
Newbie Poster
Gonbe is offline Offline
14 posts
since Jan 2010
Feb 24th, 2010
0
Re: A problem with the C preprocessor.
>>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.
Last edited by Ancient Dragon; Feb 24th, 2010 at 3:20 pm.
Sponsor
Team Colleague
Featured Poster
Reputation Points: 5608
Solved Threads: 2281
Retired and Enjoying Life
Ancient Dragon is offline Offline
21,938 posts
since Aug 2005

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in C Forum Timeline: Function will only return 0.
Next Thread in C Forum Timeline: linux shell multi piping





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC