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

    Iterator Debugging

    One of my apps links to a DLL which uses the standard containers (std::vector etc). I recently noticed that my compiler (VS2005) has an option to build with iterator debugging. From what I can gather, this option enables a warning to get generated if I try to use an invalid container iterator (e.g. if I deleted an item from a container but then carried on using an existing iterator). I'm not sure if the warning appears at compile time or run time but either way, it seemed like something that would be worth having.

    I read somewhere that for this to work, I also need to enable checked iterators. So AFAICT I should be able to use iterator debugging simply by adding these two preprocessor directives to my Debug build:-

    Code:
    _SECURE_SCL=1
    _HAS_ITERATOR_DEBUGGING=1
    I have the source code available for both the main app and the DLL - so I added those preprocessor directives in both cases and re-built. But now, when I try to launch the app I get this error and the app refuses to start:-

    The application failed to initialize properly (0x0c150002). Click on OK to terminate the application.
    If I redefine the 2 preprocessor directives to zero, the app starts working again. So I guess there's a bit more to this than I realised. Can anyone give me a hint about what I might have missed?

    Interesting development - I looked in the file yvals.h and from what I can tell, _SECURE_SCL and _HAS_ITERATOR_DEBUGGING are already defined to 1 for a Debug build. And yet if I specifically define them to 1, I get this strange run time error
    Last edited by John E; March 6th, 2013 at 07:12 AM.
    "A problem well stated is a problem half solved.” - Charles F. Kettering

  2. #2
    Join Date
    Jul 2005
    Location
    Netherlands
    Posts
    2,042

    Re: Iterator Debugging

    You need to make sure these settings are the same in all compilation units and in all modules that use the STL. How/where did you define these macros? Do you have other library dependencies that are not recompiled?
    Cheers, D Drmmr

    Please put [code][/code] tags around your code to preserve indentation and make it more readable.

    As long as man ascribes to himself what is merely a posibility, he will not work for the attainment of it. - P. D. Ouspensky

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

    Re: Iterator Debugging

    Thanks D Drmmr. I took your advice and examined all the relevant projects but no matter how closely I looked I just couldn't see anything wrong. However, by renaming libs and DLLs I eventually managed to home in on the module that was causing the problem. I opened its project and built one of the working configurations (after changing those 2 preprocessor directives) and the newly built one worked. So I compared the working configuration with my non-woriking one but I still couldn't see any difference!

    Eventually I opened the project in a text editor, deleted the non-working configuration, replaced it with the working one and everything now runs fine.

    "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