07 June, 2013

Tricky macro to add file name and line number in C++ operator new

Header file:

#if defined(_DEBUG)
  #define _CRTDBG_MAP_ALLOC

  #include <crtdbg.h>

  extern __declspec(thread) char const * t_File;
  extern __declspec(thread) int t_Line;

  inline void * __CRTDECL operator new  (size_t const size) { return ::operator new  (size, _NORMAL_BLOCK, t_File, t_Line); }
  inline void * __CRTDECL operator new[](size_t const size) { return ::operator new[](size, _NORMAL_BLOCK, t_File, t_Line); }

  #define new (t_File = __FILE__, t_Line = __LINE__, false) ? nullptr : new
#endif
Source file:
#if defined(_DEBUG)
  __declspec(thread) char const * t_File = "???";
  __declspec(thread) int t_Line = 0;
#endif

This macro doesn't work with direct operator call like operator new(...) in code.

P.S. This macro tested only on Visual Studio 2012

06 June, 2013

How to enable ARM support for desktop application in Visual Studio 2012?

Just add following in your .vcxproj file, somewhere at the beginning:

<PropertyGroup>
  <WindowsSDKDesktopARMSupport>true</WindowsSDKDesktopARMSupport>
</PropertyGroup>

P.S. Surely Windows SDK for Windows 8 has to be installed.