Thread: Limit the scope of a define?

  1. #1
    Registered User deadpoet's Avatar
    Join Date
    Jan 2004

    Question Limit the scope of a define?

    I am currently working with some pstat functions that require me to us the -D_PSTAT64 compile option. This would be fine except that it causes other pstat functions to report incorrectly. How do I limit the scope of such a statement. My first hunch is to not use the compiler flag and do something like the following:

    int main ( void ) {
      // setup code as needed ...
    #ifndef( _PSTAT64 )
    #define _PSTAT64
       // what ever needs to be done in this space....
    // What ever needs to be done out of the _PSTAT64 space...
      return( EXIT_SUCCESS );
    However, when trying to use the pstat structure that is required to have _PSTAT64 defined the compiler tells me that "the type-specifier-list contains an incomplete class ."

    Now if I remove the manually created define for _PSTAT64 and use the compiler flag -D_PSTAT64 the code compiles but it causes other pstat functions to report incorrectly.

    Can someone tell me what I am doing wrong?

    As always, I give great thanks to all those who reply.



  2. #2
    Registered User major_small's Avatar
    Join Date
    May 2003
    Join is in our Unofficial Cprog IRC channel
    Channel: #Tech

    Team Cprog Folding@Home: Team #43476
    Download it Here
    Detailed Stats Here
    More Detailed Stats
    52 Members so far, are YOU a member?
    Current team score: 1223226 (ranked 374 of 45152)

    The CBoard team is doing better than 99.16% of the other teams
    Top 5 Members: Xterria(518175), pianorain(118517), Bennet(64957), JaWiB(55610), alphaoide(44374)

    Last Updated on: Wed, 30 Aug, 2006 @ 2:30 PM EDT

  3. #3
    Yes, my avatar is stolen anonytmouse's Avatar
    Join Date
    Dec 2002
    The symbol must be defined before you #include the header, not when you use the code.

    Therefore, within a file there is generally no way to have some code that "uses" the symbol and some that does not.

    However, you can #define a symbol before #including the header in some files and not others.

    #define _PSTAT64
    #include <pstat.h>
    // _PSTAT64 space
    #include <pstat.h>
    // non _PSTAT64 space
    Of course if you then pass data types that are altered on the basis of _PSTAT64 between files you will run into trouble.

  4. #4
    Registered User deadpoet's Avatar
    Join Date
    Jan 2004
    Thanks to everyone.


Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Changing flags from a DLL?
    By RobotGymnast in forum C++ Programming
    Replies: 17
    Last Post: 10-27-2008, 01:34 PM
  2. size of an integer pointer
    By onebrother in forum C Programming
    Replies: 5
    Last Post: 07-09-2008, 11:49 AM
  3. Please STICKY this- vital to MSVC 6 dev - BASETSD.h
    By VirtualAce in forum Game Programming
    Replies: 11
    Last Post: 03-15-2005, 09:22 AM
  4. build errors migrated from dx9b to dx9c sdk
    By reanimated in forum Game Programming
    Replies: 4
    Last Post: 12-17-2004, 07:35 AM
  5. DOS, Serial, and Touch Screen
    By jon_nc17 in forum A Brief History of
    Replies: 0
    Last Post: 01-08-2003, 04:59 PM