CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums
Results 1 to 2 of 2

Thread: C++ macros

  1. #1
    Join Date
    Jun 2004

    C++ macros

    i tend to avoid macros w/ extreme prejudice. mainly this is becos they are cryptic & pollute the global namespace. i never define constants, but of crs i am stuck w/ windoze headers etc, so i can never write a class with enum{ERROR=-1}; in it

    the two things i do use is #define & #ifdef for guarding header files from multiple inclusion & other header mungeing, & token pasting for when i want multiple identifiers, &/or const cstrings based on a common symbol.

    eg something like ...

    #define DECL(n)   \
       const char name[] = #n;  \
       bool is##n();
    // ...becomes...
      const char name[] = "Thing";   
      bool isThing();

    does anybody kno of any other uses for C preprocessor macros that cant be achieved any other way?

  2. #2
    Join Date
    Jun 2004
    you mean like in

    inline bool ShortFrequentlyCalledFunction()
       return rand()%2 ? true:false;


Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Windows Mobile Development Center

Click Here to Expand Forum to Full Width

On-Demand Webinars (sponsored)