Thread: A lot of warnings C4003 & errors C2059 after using VC's native CRT Debugger

  1. #1
    In the Land of Diddly-Doo g4j31a5's Avatar
    Join Date
    Jul 2006
    Posts
    476

    A lot of warnings C4003 & errors C2059 after using VC's native CRT Debugger

    Hi, currently in my bug hunting endeavor, I am stumbled on some errors. I tried implementing the VC's native CRT debugger / memory leak detector from this web: http://msdn.microsoft.com/en-us/libr...h3(VS.80).aspx. But now I can't compile my code because it produces lots of warnings C4003 & errors C2059 like the quote below:

    19>c:\convex.h(109) : warning C4003: not enough actual parameters for macro 'free'
    19>c:\convex.h(109) : error C2059: syntax error : ','
    It seems like there's a 'free' macro that has already been defined. But the funny thing is, all of the instance of 'free' are regarded as errors. Even if they are a member function of a class. For example, the above quoted error is from a member function of a Convex class (as in "Convex::free()" ). How do I solve this besides having to undef the macro? I mean, if I undef-ed the macro, what's the point of using the CRT debugger / memory leak detector in the first place, right?

    Thanks a lot in advance.
    ERROR: Brain not found. Please insert a new brain!

    “Do nothing which is of no use.” - Miyamoto Musashi.

  2. #2
    Kernel hacker
    Join Date
    Jul 2007
    Location
    Farncombe, Surrey, England
    Posts
    15,677
    Show us the code (the macro or whatever).

    --
    Mats
    Compilers can produce warnings - make the compiler programmers happy: Use them!
    Please don't PM me for help - and no, I don't do help over instant messengers.

  3. #3
    C++まいる!Cをこわせ!
    Join Date
    Oct 2007
    Location
    Inside my computer
    Posts
    24,654
    It seems to me that you would have to push the macro, undef it, then pop the macro where appropriate. Macros are evil; which is also why they are typically avoided.
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.

  4. #4
    In the Land of Diddly-Doo g4j31a5's Avatar
    Join Date
    Jul 2006
    Posts
    476
    First, thank you for the replies guys.

    Quote Originally Posted by matsp View Post
    Show us the code (the macro or whatever).

    --
    Mats
    Well, this is from crtdbg.h

    Code:
    #ifdef  _CRTDBG_MAP_ALLOC
    
    #define   malloc(s)             _malloc_dbg(s, _NORMAL_BLOCK, __FILE__, __LINE__)
    #define   calloc(c, s)          _calloc_dbg(c, s, _NORMAL_BLOCK, __FILE__, __LINE__)
    #define   realloc(p, s)         _realloc_dbg(p, s, _NORMAL_BLOCK, __FILE__, __LINE__)
    #define   _recalloc(p, c, s)    _recalloc_dbg(p, c, s, _NORMAL_BLOCK, __FILE__, __LINE__)
    #define   _expand(p, s)         _expand_dbg(p, s, _NORMAL_BLOCK, __FILE__, __LINE__)
    #define   free(p)               _free_dbg(p, _NORMAL_BLOCK)
    ...
    #endif  /* _CRTDBG_MAP_ALLOC */
    I think it is used to wrap the new, delete, malloc, realloc, calloc, free, etc so that it will keep a record of the values of the memory being allocated, is it freed in the end or not, etc. Just like a memory leak detector / profiler. And it is native in Visual C++ (AFAIK).


    Quote Originally Posted by Elysia View Post
    It seems to me that you would have to push the macro, undef it, then pop the macro where appropriate. Macros are evil; which is also why they are typically avoided.
    That would mean re-writing the whole 400+ header and source files with 2000+ lines of code each (in average). Great.

    Is there any other easier way?

    Thanks again.
    ERROR: Brain not found. Please insert a new brain!

    “Do nothing which is of no use.” - Miyamoto Musashi.

  5. #5
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,659
    > That would mean re-writing the whole 400+ header and source files with 2000+ lines of code each (in average).
    And that would indeed be a big mistake.

    Did you heed this warning on the usage of crtdbg?
    Quote Originally Posted by msdn
    The #include statements must be in the order shown here. If you change the order, the functions you use may not work properly.
    I use this quite a lot, so there's probably something messed up with the general usage, rather than any specific instance of calling free().
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

  6. #6
    Cat without Hat CornedBee's Avatar
    Join Date
    Apr 2003
    Posts
    8,895
    How do I solve this besides having to undef the macro?
    You can push/pop the macro before/after the Convex header.
    You can modify the header to avoid the macro:
    Code:
    #define NMS /* No Macro Substitution */
    free NMS ();
    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

  7. #7
    In the Land of Diddly-Doo g4j31a5's Avatar
    Join Date
    Jul 2006
    Posts
    476
    @all

    Okay, I've moved the #include statement just before the main() function ( the last #include statement before main() ). And it's working, I think. Thanks a lot guys.
    Last edited by g4j31a5; 11-06-2008 at 04:11 AM.
    ERROR: Brain not found. Please insert a new brain!

    “Do nothing which is of no use.” - Miyamoto Musashi.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. An error is driving me nuts!
    By ulillillia in forum C Programming
    Replies: 5
    Last Post: 04-04-2009, 09:15 PM
  2. Trouble with Windows/DirectX programming
    By bobbelPoP in forum Windows Programming
    Replies: 16
    Last Post: 07-08-2008, 02:27 AM
  3. more then 100errors in header
    By hallo007 in forum Windows Programming
    Replies: 20
    Last Post: 05-13-2007, 08:26 AM
  4. We Got _DEBUG Errors
    By Tonto in forum Windows Programming
    Replies: 5
    Last Post: 12-22-2006, 05:45 PM
  5. Using VC Toolkit 2003
    By Noobwaker in forum Windows Programming
    Replies: 8
    Last Post: 03-13-2006, 07:33 AM