In pthread.h
, one could find the following definition:
/* Detach state. */
enum
{
PTHREAD_CREATE_JOINABLE,
#define PTHREAD_CREATE_JOINABLE PTHREAD_CREATE_JOINABLE
PTHREAD_CREATE_DETACHED
#define PTHREAD_CREATE_DETACHED PTHREAD_CREATE_DETACHED
};
Why this definition mixing enum and defines? How to interpret it? Besides, the #define
is defining something to the same.
This is because PTHREAD_CREATE_JOINABLE
and PTHREAD_CREATE_DETACHED
need to be used in #ifdef
statements (here is an example of source code where it is used in this way). The authors needed to define their names to their values, otherwise the preprocessor would not let you use the corresponding enum
value.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With