I know the words "portable" and "macro" don't often go together, but my code is generally riddled with #ifdef _DEBUG
tags (I use VS2012) that confirm desired outcomes. I want to make my code portable to Unix systems.
My understanding, based on this post, is that Visual Studio uses _DEBUG
and the C-standard uses NDEBUG
, but that their functions are different (_DEBUG
flags debug mode, NDEBUG
flags assertions).
If I want my code to be as portable as possible, should I use #ifndef NDEBUG
if I only ever want those lines of code to run when asserts are active? What are the consequences of this within Visual Studio? It seems to work but I want to make sure there's nothing I'm missing; ie. why would microsoft use _DEBUG
when there's a perfectly good C-standard alternative? Historic reasons?