0

Here is the code:

void DBG() { cerr << "]" << endl; }
template<class H, class... T> void DBG(H h, T... t) {
    cerr << to_string(h); if (sizeof...(t)) cerr << ", ";
    DBG(t...); }

#ifdef _DEBUG
#define dbg(...) cerr << "LINE(" << __LINE__ << ") -> [" << #__VA_ARGS__ << "]: [", DBG(__VA_ARGS__)
#else
#define dbg(...) 0
#endif

Im currently using g++ on vs code on a mac and whenever I run my program using this and for example I write dbg(10) on main the program does not even run and does not do anything(it outputs nothing).

How can I change this code so it would work on g++ without having to download clang? Note: I saw some people use #ifdef LOCAL instead of #ifdef _DEBUG but it still doesn't work for me(does not output anything). How do I get #ifdef LOCAL or #ifdef _DEBUG to work on g++?

Mohsen Alyafei
  • 4,765
  • 3
  • 30
  • 42
Rainier1
  • 73
  • 6
  • _DEBUG is from MSVC, try #ifdef NDEBUG – JCWasmx86 Jul 12 '20 at 14:36
  • @JCWasmx86 nope still doesn't work for me – Rainier1 Jul 12 '20 at 14:38
  • It's the other way around "NDEBUG" means not debugging, so the condition should be `#ifndef NDEBUG`. Separately, it's best practice to reserve all-uppercase multi-letter names for preprocessor defines and never use them for other purposes, so I'd suggest calling your function "dbg" and your macro "DBG". – Tony Delroy Jul 12 '20 at 14:39
  • Does this answer your question? [How to use #ifdef \_DEBUG on Linux?](https://stackoverflow.com/questions/9034700/how-to-use-ifdef-debug-on-linux) – Adrian Mole Jul 12 '20 at 14:41
  • @TonyDelroy What about if I want to use #ifdef LOCAL? What do I have to replace that with because #ifdef LOCAL does not also work. Or is it the same thing? – Rainier1 Jul 12 '20 at 14:41
  • @AdrianMole I think this is a different topic to that... – Rainier1 Jul 12 '20 at 14:43
  • I've never heard of a preprocessor define called `LOCAL` - is that a Windows/VisualC++ or MacOS thing? If you want to know what preprocessor defines your compiler has by default, check its documentation. Most compilers have some command line options to get them to output a list of such defines. – Tony Delroy Jul 12 '20 at 14:43
  • @TonyDelroy I think its a windows thing – Rainier1 Jul 12 '20 at 14:44

0 Answers0