Rainier1
Rainier1

Reputation: 71

having difficulty understanding assert macro

I recently found this snippet of code and i'm a bit confused.

#ifdef LOCAL //  chk -> fake assert
    #define dbg(...) cerr << "Line(" << __LINE__ << ") -> [" << #__VA_ARGS__ << "]: [", DBG(__VA_ARGS__)
    #define chk(...) if (!(__VA_ARGS__)) cerr << "Line(" << __LINE__ << ") -> function(" \
         << __FUNCTION__  << ") -> CHK FAILED: (" << #__VA_ARGS__ << ")" << "\n", exit(0);
#else
    #define dbg(...) 0
    #define chk(...) 0
#endif

I clearly understand what the debug does but I have no idea what "chk" does and how I should use this in my code. Thank you

Upvotes: 0

Views: 82

Answers (1)

Łukasz Ślusarczyk
Łukasz Ślusarczyk

Reputation: 1864

dbg prints message to cerr in every case together with macro arguments regardless of whether arguments evaluate to true or false

On the other hand chk macro prints message only in case when macro arguments evaluate to false and then calls exit

Upvotes: 1

Related Questions