Thread: MSVC 2005 bug?

  1. #1
    Registered User VirtualAce's Avatar
    Join Date
    Aug 2001
    Posts
    9,607

    MSVC 2005 bug?

    I've noticed that MSVS 2005 seems to get confused when you use function names that have been defined as macros at some point prior to your declaration.
    I have a hash table class that has a function called GetObject. It is very clearly GetObject in the code but 2005 is complaining about GetObjectA not being a part of HashTable.
    To get around it I did this at the top of the cpp using HashTable:

    #undef GetObject


    Is this a bug? Shouldn't the compiler see that my GetObject() is a this call and requires an object of type HashTable and that my GetObject() is not called GetObjectA()?

    This link applies to C# but I think it answers my question:
    http://support.microsoft.com/kb/888267

    It's not a bug in the compiler but is caused by windows.h polluting the global namespace. It has a macro that turns GetObject into GetObjectA or GetObjectW.
    Last edited by VirtualAce; 01-09-2010 at 08:11 PM.

  2. #2
    Cat without Hat CornedBee's Avatar
    Join Date
    Apr 2003
    Posts
    8,895
    Shouldn't the compiler see that my GetObject() is a this call and requires an object of type HashTable and that my GetObject() is not called GetObjectA()?
    That's what makes the preprocessor so dangerous. It's just a text replacement engine. Classes? Objects? Never heard of them.

    windows.h is a disaster. They had the audacity to define macros called min and max. Worse, they're unsanitary:
    Code:
    int x = min(y++, z++);
    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

  3. #3
    Ex scientia vera
    Join Date
    Sep 2007
    Posts
    477
    Quote Originally Posted by CornedBee View Post
    That's what makes the preprocessor so dangerous. It's just a text replacement engine. Classes? Objects? Never heard of them.

    windows.h is a disaster. They had the audacity to define macros called min and max. Worse, they're unsanitary:
    Code:
    int x = min(y++, z++);
    That right there is the reason why every programmer has heard a newbie ask "What do I need to know to 'learn the windows API'?"

    All the macros, and typedefs and so on, almost make for a whole new language on top of C/C++. At least if you're a newbie looking at it. What's a DWORD?

    You could take almost any other API for whatever, and a newbie would realize it was just a collection of functions for him to use in specific scenarios. But the windows API - not so much.
    "What's up, Doc?"
    "'Up' is a relative concept. It has no intrinsic value."

  4. #4
    Registered User VirtualAce's Avatar
    Join Date
    Aug 2001
    Posts
    9,607
    I think I've ran into this before and posted something about it. It's really annoying when a macro somewhere else conflicts with method names in my classes. Who would ever take a generic name like GetObject and redefine it to GetObjectA or GetObjectW? As if GetObject is a very specific function name.

    My hash table holds objects so I changed the names from Get, Add, and Remove to GetObject, AddObject, and RemoveObject to make them clearer to the user. Guess that was a bad idea.

  5. #5
    Officially An Architect brewbuck's Avatar
    Join Date
    Mar 2007
    Location
    Portland, OR
    Posts
    7,396
    It's Microsoft. They think they own all names in the universe. We recently had the exact same problem, though I can't remember what the function was called.

    Suck it up, rename your function and move on. I know it sucks.
    Code:
    //try
    //{
    	if (a) do { f( b); } while(1);
    	else   do { f(!b); } while(1);
    //}

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. If you must port to .NET 2005, read this thread.
    By VirtualAce in forum A Brief History of Cprogramming.com
    Replies: 3
    Last Post: 10-22-2007, 06:51 AM
  2. memcpy working strangely in msvc 2005
    By *DEAD* in forum C++ Programming
    Replies: 1
    Last Post: 06-15-2007, 09:50 AM
  3. MSVC 2005 .NET Intellisense issues
    By VirtualAce in forum A Brief History of Cprogramming.com
    Replies: 6
    Last Post: 09-19-2006, 03:04 PM
  4. MSVC 2005 problem
    By l2u in forum Windows Programming
    Replies: 1
    Last Post: 05-13-2006, 05:30 PM
  5. MSVC 2k3 7.1 bug?
    By RITZ in forum C++ Programming
    Replies: 3
    Last Post: 03-26-2006, 02:50 PM