Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What does "#if cpp" means in C file?

Tags:

c

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 */
like image 842
interskh Avatar asked Sep 09 '26 13:09

interskh


1 Answers

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
like image 66
Evan Teran Avatar answered Sep 12 '26 05:09

Evan Teran



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!