根据编译时常量,使用相同的标识符 #define 或类型定义是否被认为是可接受的做法?
Is it considered acceptable practice to have the same identifier #define'd or typedef'ed, depending on compile-time constants?
"英特尔数学内核库"在头文件中包含以下代码:
#ifndef MKL_Complex16
typedef
struct _MKL_Complex16 {
double real;
double imag;
} MKL_Complex16;
#endif
正如这里所描述和讨论的,用户可以通过编写来覆盖这个结构定义
#define MKL_Complex16 std::complex<double>
在包括头文件之前。对于这一行,MKL_Complex16
是#define
'd,这意味着字符串只是到处替换为文字字符std::complex<double>
。如果不是,则为typedef
’ed,这将为编译器提供更多信息。
这被认为是可以接受的做法吗?我想它一定是,因为它是由英特尔实现的。但在调试某些代码时,我发现它非常令人困惑。
这看起来很疯狂。我会非常不愿意在构建环境中传递实际的代码。如果有什么不同的话,请使用更高级别的标志:
#ifndef HAVE_STD_COMPLEX
struct MKL_Complex16 { double real; double img; };
#else
# include <complex>
typedef std::complex<double> MKL_Complex16;
#endif
相关文章:
- 在提升multi_index容器中,是否定义了"default index"?
- sprintf(b, "%" ) 是否定义了?
- 重载虚拟行为是否定义良好?
- 它是否定义了哪些算法可以接受可变 lambda 的实现?
- 如何检查是否定义了固定宽度的整数
- &*NULL 在C++中是否定义良好?
- C++标准是否定义了结构中成员函数的函数内定义是否必须具有静态链接?
- 将以"_[a-z0-9]"开头和"using"的标识符导入全局命名空间是否定义良
- SFINAE 检测是否定义了类型
- 标准是否定义了共同基础?
- 根据是否定义了另一个宏来评估宏
- 获取未初始化对象成员的地址是否定义良好?
- 如何测试是否定义了结构的成员 (c++)
- 如何测试标准库中是否定义了 std::remove_cvref
- 对非活跃的工会成员使用"std::addressof"是否定义明确
- C++模板 - 几个专业 - 行为是否定义?
- 如何检查是否定义了标头保护
- C++14 是否定义了无符号 int 的填充位上的按位运算符的行为
- C / C++中无符号整数的减法和比较是否定义良好?
- 在比较中使用已强制转换为另一种类型的函数指针是否定义良好?