根据编译时常量,具有相同的标识符 #define'd 或 typedef'ed 是否被认为是可接受的做法?

发布于 2024-12-26 22:32:30 字数 811 浏览 6 评论 0 原文

英特尔数学核心函数库在头文件中包含这段代码:

#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 > 无处不在。如果不是,则对其进行 typedef 编辑,从而为编译器提供更多信息。

这被认为是可接受的做法吗?我想一定是这样,因为它是由英特尔实现的。但我在尝试调试一些代码时发现它非常令人困惑。

The Intel Math Kernel Library contains this bit of code in a header file:

#ifndef MKL_Complex16
typedef
struct _MKL_Complex16 {
    double real;
    double imag;
} MKL_Complex16;
#endif

as described here and discussed here, this struct definition can be over-ridden by the user by writing

#define MKL_Complex16 std::complex<double>

before the header file is included. With this line, MKL_Complex16 is #define'd, which means the character string is just replaced with the literal characters std::complex<double> everywhere. If not, it is typedef'ed, which gives the compiler more information.

Is this considered acceptable practice? I guess it must be, since it's implemented by Intel. But I found it very confusing while trying to debug some code.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

喜你已久 2025-01-02 22:32:30

这看起来很疯狂。我非常不愿意通过构建环境传递实际代码。如果有的话,请使用更高级别的标志:

#ifndef HAVE_STD_COMPLEX
    struct MKL_Complex16 { double real; double img; };
#else
#  include <complex>
   typedef std::complex<double> MKL_Complex16;
#endif

This looks insane. I would be very reluctant to pass actual code through the build environment. If anything, use a higher-level flag:

#ifndef HAVE_STD_COMPLEX
    struct MKL_Complex16 { double real; double img; };
#else
#  include <complex>
   typedef std::complex<double> MKL_Complex16;
#endif
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文