看起来你有你的#define
落后。如果你想在这两个平台上使用__func__
和WIN32有__FUNCTION__
但不__func__
,你需要做的,而不是:
#if defined (WIN32)
#define __func__ __FUNCTION__
#endif
有可能是一个更好的方式来知道你是否需要定义__func__
与否,但这个快速的黑客应该做的伎俩。
请记住,在支持__FUNCTION__
和__func__
关键字编译器,他们不是宏,所以你不能做以下的(因为#ifndef __func__
无效):
#ifndef __func__
#define __func__ __FUNCTION__
#endif
从C99规格:
6.4.2.2 Predefined identifiers
1 The identifier __func__
shall be implicitly declared by the translator as if, immediately following the opening brace of each function definition, the declaration
static const char __func__[] = "function-name";
appeared, where function-name is the name of the lexically-enclosing function.
您应该使用#if defined(_MSC_VER)而不是#if defined(_WIN32)。问题不在于你使用的是哪个操作系统。问题是你正在使用哪个编译器。 – 2015-01-17 17:54:21