CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 3 of 3
  1. #1
    John E is offline Elite Member Power Poster
    Join Date
    Apr 2001
    Location
    Manchester, England
    Posts
    4,835

    # character (in string generation ?)

    I found this code in a header file here... it starts with a declaration of various 'DebugBit' types, followed by the declaration for a function which prints out some debug text:-

    Code:
    namespace DEBUG {
    	extern DebugBits State;
    	extern DebugBits Properties;
    	extern DebugBits Name;
    	extern DebugBits Locale;
    
    	// and various others...
    
    	}
    
    void debug_print (const char* prefix, std::string str);
    These get followed by a preprocessor directive for using the above:-

    Code:
    #define DEBUG_TRACE(bits, str) { debug_print (# bits, str); }
    And later in the code, it tends to get used something like this:-

    Code:
    DEBUG_TRACE (DEBUG::State, "whatever");
    I think that the intention of # bits is maybe to convert parameter 1 from an enumeration into the equivalent string - so DEBUG::State would get converted to the string "Debug::State". This apparently works for other compilers but MSVC gives me C2014 "preprocessor command must start as first nonwhite space"

    Does this not work in MSVC or am I misunderstanding something
    "A problem well stated is a problem half solved.” - Charles F. Kettering

  2. #2
    VictorN's Avatar
    VictorN is offline Super Moderator Power Poster
    Join Date
    Jan 2003
    Location
    Hanover Germany
    Posts
    20,396

    Re: # character (in string generation ?)

    Hi John,
    did you try to remove the space between # and bits ?
    Victor Nijegorodov

  3. #3
    John E is offline Elite Member Power Poster
    Join Date
    Apr 2001
    Location
    Manchester, England
    Posts
    4,835

    Re: # character (in string generation ?)

    Thanks Victor. I tried #bits and it worked. So I then returned to # bits and that now works too!! There must've been some weird character lurking there that wasn't visible.
    "A problem well stated is a problem half solved.” - Charles F. Kettering

Posting Permissions

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





Click Here to Expand Forum to Full Width

Featured