0
如果可用,我會使用函數。從手冊頁代碼:如何使用Glibc功能測試宏?
#define _GNU_SOURCE /* See feature_test_macros(7) */
#include <pthread.h>
int pthread_setname_np(pthread_t thread, const char *name);
int pthread_getname_np(pthread_t thread,
char *name, size_t len);
它是安全的只是做這樣的(不包括沒有定義):包括不需要
#ifdef _GNU_SOURCE
pthread_setname_np(pthread_self(), "mythread");
#endif
因爲C++ #include <thread>
,我使用似乎拉pthreads
。 _GNU_SOURCE
始終在libstdc++
中啓用,如果它被禁用 - 代碼將仍然編譯。
我錯過了什麼嗎?
您是否閱讀過[feature_test_macros(7)](http://man7.org/linux/man-pages/man7/feature_test_macros.7.html)? –
@BasileStarynkevitch,是的。它關於控制標準庫提供的內容。我對激活我的程序功能感興趣,具體取決於構建的方式。 – Velkan
看來這個問題被標記爲'c',但實際問題討論了'C++'。這些是不同的語言。請選擇一個。 – user3629249