tags:

views:

428

answers:

3

I am working on some source code these days. In some codes, I find these at the head. Dunno what it means. Any ideas?

#include "pth_p.h"

#if cpp

#ifndef PTH_DEBUG

#define pth_debug1(a1)                     /* NOP */
#define pth_debug2(a1, a2)                 /* NOP */
#define pth_debug3(a1, a2, a3)             /* NOP */
#define pth_debug4(a1, a2, a3, a4)         /* NOP */
#define pth_debug5(a1, a2, a3, a4, a5)     /* NOP */
#define pth_debug6(a1, a2, a3, a4, a5, a6) /* NOP */

#else

#define pth_debug1(a1)                     pth_debug(__FILE__, __LINE__, 1, a1)
#define pth_debug2(a1, a2)                 pth_debug(__FILE__, __LINE__, 2, a1, a2)
#define pth_debug3(a1, a2, a3)             pth_debug(__FILE__, __LINE__, 3, a1, a2, a3)
#define pth_debug4(a1, a2, a3, a4)         pth_debug(__FILE__, __LINE__, 4, a1, a2, a3, a4)
#define pth_debug5(a1, a2, a3, a4, a5)     pth_debug(__FILE__, __LINE__, 5, a1, a2, a3, a4, a5)
#define pth_debug6(a1, a2, a3, a4, a5, a6) pth_debug(__FILE__, __LINE__, 6, a1, a2, a3, a4, a5, a6)

#endif /* PTH_DEBUG */

#endif /* cpp */
+4  A: 

This is an example of a preprocessor directive that allows you to test an expression at compilation time. Here is a good explanation.

Andrew Hare
+8  A: 

it is testing if some constant named cpp that is visible to the preprocessor (is likely a macro) is non-zero.

Usual convention is that macros should be all uppercase so that they are more obvious, but they don't have to be (as is apparently the case here).

My guess is that it stands for c++ and one of the included headers (perhaps pth_p.h?) defines it if a c++ compiler is being used. If this is the case, there are more standard things to use which are preferred such as this:

#ifdef __cplusplus
Evan Teran
+2  A: 

I suspect that this is checking whether the code is being compiled by a c++ compiler or a c compiler. If C++, the macros are defined if there is also the PTH_DEBUG flag set. I suspect that this flag would be set in a call to the compiler. If C, the macros are not defined. Why that is the case depends on what pth_debug macros are intended to do.

Steve Rowe