#undef

This is a discussion on #undef within the C++ Programming forums, part of the General Programming Boards category; I'm having trouble with #undef... it doesn't seem to be changing anything... at the top of my header file I ...

  1. #1
    Registered User
    Join Date
    Sep 2002
    Posts
    417

    #undef

    I'm having trouble with #undef... it doesn't seem to be changing anything... at the top of my header file I have this:

    #define BOOST_ANY_TYPECHECK

    I want, inside the template function change_type, to use #undef to undefine it, run the function, and then redefine it if it was defined.

    This doesn't seem to be working... is it local to the function itself if you use it inside a function?

  2. #2
    Senior Member joshdick's Avatar
    Join Date
    Nov 2002
    Location
    Phildelphia, PA
    Posts
    1,146
    The preprocessor runs before the compiler, so preprocessor directives are run before your code is compiled. I'm not sure how much this helps, but I didn't take the time to fully understand your problem. It's late
    FAQ

    "The computer programmer is a creator of universes for which he alone is responsible. Universes of virtually unlimited complexity can be created in the form of computer programs." -- Joseph Weizenbaum.

    "If you cannot grok the overall structure of a program while taking a shower, you are not ready to code it." -- Richard Pattis.

  3. #3
    Registered User
    Join Date
    Sep 2002
    Posts
    417
    I want to change a define... maybe I should try using a global variable... lemme try that real quick.

    Nevermind, its useless... I still need to find why the templates aren't changing each time or it won't work.
    Last edited by Trauts; 05-05-2003 at 08:52 PM.

  4. #4
    Registered User
    Join Date
    Apr 2003
    Posts
    2,662
    "is it local to the function itself if you use it inside a function?"

    My book says that #define(and therefore #undef) does not respect scope and cannot be bound within a namespace.
    Last edited by 7stud; 05-06-2003 at 12:17 AM.

  5. #5
    Cat without Hat CornedBee's Avatar
    Join Date
    Apr 2003
    Posts
    8,893
    But it might still not help you. I don't know what BOOST_ANY_TYPECHECK does, but if it changes the behaviour of the boost headers then undefining or defining it for one of your functions makes no difference. It only makes a difference at the point where you include the boost headers. Like with the windows header and _WIN32_LEAN_AND_MEAN:
    Code:
    // _WIN32_LEAN_AND_MEAN tells windows.h not to include
    // rarely used headers, thus fastening compilation.
    #define _WIN32_LEAN_AND_MEAN
    #include <windows.h>
    
    // ...
    int WinMain(...
    // ...
    
    
    // We want multimedia functions in this function, so let's undo
    // the non-inclusion:
    #undef _WIN32_LEAN_AND_MEAN
    void DoMultimedia(int type)
    {
      // ...
    }
    #define _WIN32_LEAN_AND_MEAN
    
    // But this DOESN'T WORK!
    // It only makes a difference at the point where windows.h gets included.
    All the buzzt!
    CornedBee

    "There is not now, nor has there ever been, nor will there ever be, any programming language in which it is the least bit difficult to write bad code."
    - Flon's Law

  6. #6
    Veni Vidi Vice
    Join Date
    Aug 2001
    Posts
    343
    Iīm not sure but I think your answer is here

    Pay attention to Polymorphic OOP reply.
    01000111011011110110111101100100 011101000110100001101001011011100110011101110011 01100100011011110110111001110100 01100011011011110110110101100101 01100101011000010111100101110011 0110100101101110 01101100011010010110011001100101
    Good things donīt come easy in life!!!

  7. #7
    Cat without Hat CornedBee's Avatar
    Join Date
    Apr 2003
    Posts
    8,893
    Those are entirely different matters.
    All the buzzt!
    CornedBee

    "There is not now, nor has there ever been, nor will there ever be, any programming language in which it is the least bit difficult to write bad code."
    - Flon's Law

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 6
    Last Post: 02-04-2006, 08:01 PM
  2. Round Robin Scheduling using c.
    By eclipt in forum C Programming
    Replies: 8
    Last Post: 12-28-2005, 03:58 PM
  3. NAQ: Everything you never wanted to know about CPP
    By evildave in forum C Programming
    Replies: 21
    Last Post: 12-12-2005, 09:56 AM
  4. Replies: 1
    Last Post: 03-17-2005, 07:53 AM
  5. noob problem with a number generator
    By Amoreldor in forum C Programming
    Replies: 14
    Last Post: 03-10-2005, 09:39 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21