locked
_DEBUG_POINTER in VS 2017 RRS feed

  • Question

  • Visual Studio 2017 Community VC++, Windows 7 Pro SP1

    Code:

    template<class _InIt, class _Pr> 
    inline _InIt find_nearest(_InIt _First, _InIt _Last, _Pr _Pred)
    {	
     	_DEBUG_RANGE(_First, _Last);
     	_DEBUG_POINTER(_Pred);
    
      _InIt _NearestIt = _First; // Find first satisfying _Pred
    	for (; _First != _Last; ++_First)
      {
    		if (_Pred(*_First))
    			break;
        _NearestIt = _First;
      }
    
    	return (_NearestIt);
    }
    
    

    In VS 2015 Community it is compiled just fine; in VS 2017 Community the compiler complains "Can't find definition of _DEBUG_POINTER.'

    Any help?

    In MFS App

    Wednesday, June 28, 2017 5:42 PM

Answers

  • Yes, David's original reply.

    As he rightly stated, Microsoft changed the implementation of the STL and _DEBUG_POINTER went along with it.

    You should check the STL code that you copied _DEBUG_POINTER from to see how it has been updated and change your own code accordingly.

    This is one of the problems with using internal and undocumented STL features in your own code, they can change and the code that you write that relies on them will break.


    This is a signature. Any samples given are not meant to have error checking or show best practices. They are meant to just illustrate a point. I may also give inefficient code or introduce some problems to discourage copy/paste coding. This is because the major point of my posts is to aid in the learning process.

    • Marked as answer by Geoyar Tuesday, April 3, 2018 8:15 PM
    Tuesday, April 3, 2018 6:53 PM

All replies

  • >In VS 2015 Community it is compiled just fine; in VS 2017 Community the compiler complains "Can't find definition of _DEBUG_POINTER.'

    If it was never documented then it's probably been removed/changed in changes to STL code.

    I'd examine the MS code where you presumably copied it from originally and see what it is in the 2017 sources.

    Dave

    Wednesday, June 28, 2017 7:39 PM
  • Thank for reply.

    It was years ago, but, as I remember, I have copied and pasted some piece (probably, std::find) from header 'algorithm' and changed it to get this template.

    Anyway, both _DEBUG macros were in std algorithm header because I never knew what it is.

    Thursday, June 29, 2017 1:07 AM
  • Hi friend,

    Did you set the project to debug mode in VS2017 while you were compiling it?

    If the code is compiled with DEBUG defined, probably in a debug build, you see the output. For a release build, you don't.

    Best regards,

    Fletcher


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.


    Monday, July 3, 2017 3:23 AM
  • Thanks for reply.

    Yes, it was in DEBUG mode.

    Usually macros like _DEBUG_RANGE, _DEBUG_POINTER are just ignored bu builder while it builds the RELEASE mode.

    The problem I reported is different: there is no definition for _DEBUG_POINTER in VC++ 2017 headers.

    Monday, July 3, 2017 4:55 PM
  • Hi Geoyar,

    As the issue is more related to C++, I will move it to C++ forum for you to get a quick and precise answer.

    Thanks for your understanding.

     

     

    Best regards,

    Fletcher


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.


    Tuesday, July 4, 2017 3:01 AM
  • Hi Geoyar,

    thanks for posting here.

    >>In VS 2015 Community it is compiled just fine; in VS 2017 Community the compiler complains "Can't find definition of _DEBUG_POINTER.'

    As tested in my vs2015 and vs2017, it all works fine. For example, vs2017:

    Have you installed STL feature with your vs2017? Please provide more information or steps about your issue, so that we could find the root cause for you.

    Best Regards,
    Sera Yu


    MSDN Community Support<br/> Please remember to click &quot;Mark as Answer&quot; the responses that resolved your issue, and to click &quot;Unmark as Answer&quot; if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact <a href="mailto:MSDNFSF@microsoft.com">MSDNFSF@microsoft.com</a>.

    Tuesday, July 4, 2017 5:50 AM
  • Dear Yu, thanks for reply.

    I think you made a mistake. Your 'main' function just returns zero, it does not use 'find nearest'.

    According to C++ rules, the compiler does not do any attempt to instantiate (ergo, compile) the template; it just checks syntax and goes away.

    But if you will try to use the template, the compiler will try to instantiate (to compile) the template for some given to it type, will go for _DEBUG_POINTER and will not find the definition of it.

    Try this code:

    // DebPtr.cpp : Defines the entry point for the console application.
    //
    
    #include "stdafx.h"
    #include <vector>
    
    template<class _InIt, class _Pr>
    inline _InIt find_nearest(_InIt _First, _InIt _Last, _Pr _Pred)
    {
      _DEBUG_RANGE(_First, _Last);
      _DEBUG_POINTER(_Pred);
    
      _InIt _NearestIt = _First; // Find first satisfying _Pred
      for (; _First != _Last; ++_First)
      {
        if (_Pred(*_First))
          break;
        _NearestIt = _First;
      }
    
      return (_NearestIt);
    }
    
    template <typename T>
    struct coord_in_range
    {
      T _lim;
    
      coord_in_range(T lim) :_lim(lim) {}
      inline bool operator () (T val)
      {
        return val > _lim;
      }
    };
    
    using namespace std;
    
    
    int main()
    {
      vector<int> vT = {5, 2, 7, 9, 1};
    
      vector<int>::iterator resIt = find_nearest(vT.begin(), vT.end(), coord_in_range<int>(8));
      return 0;
    }
    
    

    Compiler complains:

    1>------ Build started: Project: DebPtr, Configuration: Debug Win32 ------
    1>DebPtr.cpp
    1>c:\vs2017\projects\debptr\debptr\debptr.cpp(11): error C3861: '_DEBUG_POINTER': identifier not found
    1>c:\vs2017\projects\debptr\debptr\debptr.cpp(43): note: see reference to function template instantiation '_InIt find_nearest<std::_Vector_iterator<std::_Vector_val<std::_Simple_types<int>>>,coord_in_range<int>>(_InIt,_InIt,_Pr)' being compiled
    1>        with
    1>        [
    1>            _InIt=std::_Vector_iterator<std::_Vector_val<std::_Simple_types<int>>>,
    1>            _Pr=coord_in_range<int>
    1>        ]
    1>Done building project "DebPtr.vcxproj" -- FAILED.
    ========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========

    Tuesday, July 4, 2017 9:46 PM
  • Hi, I'm experiencing a similar error.  A reference to _DEBUG_POINTER' used to compile under an older VS version, but gets a compiler error under VS2017.  It happens whether compiling for Debug or Release.

    Did you ever get an answer or a solution to this ?

    Thanks


    • Edited by JMP57 Tuesday, April 3, 2018 6:16 PM
    Tuesday, April 3, 2018 6:11 PM
  • Yes, David's original reply.

    As he rightly stated, Microsoft changed the implementation of the STL and _DEBUG_POINTER went along with it.

    You should check the STL code that you copied _DEBUG_POINTER from to see how it has been updated and change your own code accordingly.

    This is one of the problems with using internal and undocumented STL features in your own code, they can change and the code that you write that relies on them will break.


    This is a signature. Any samples given are not meant to have error checking or show best practices. They are meant to just illustrate a point. I may also give inefficient code or introduce some problems to discourage copy/paste coding. This is because the major point of my posts is to aid in the learning process.

    • Marked as answer by Geoyar Tuesday, April 3, 2018 8:15 PM
    Tuesday, April 3, 2018 6:53 PM
  • Ok, thank you.  So everything below David's reply on 6/28/17 is just noise and should be ignored...
    Tuesday, April 3, 2018 7:33 PM
  • I have marked as answer the post of Darran Rowe below. _DEBUG_POINTER does not exist animore, so you have to check last version ogf STL header you are using.
    • Edited by Geoyar Tuesday, April 3, 2018 8:20 PM
    Tuesday, April 3, 2018 8:19 PM