Clang,这些类型如何冲突?

发布于 2025-02-02 14:40:50 字数 567 浏览 3 评论 0原文

试图用clang(在Windows上)编译Python解释器,我得到了(经过一些改进):

c:\Python-3.10.4\Python\pytime.c:603:5: error: conflicting types for '_PyTime_AsTimeval'
int _PyTime_AsTimeval(_PyTime_t t, struct timeval *tv, _PyTime_round_t round)
    ^
C:\Python-3.10.4\Include/cpython/pytime.h:126:5: note: previous declaration is here
int _PyTime_AsTimeval(_PyTime_t t, struct timeval *tv, _PyTime_round_t round);
    ^

嗯...这些看起来对我来说并不矛盾!我想念什么? Python代码在这些声明中是否有不寻常的事情?有没有办法让clang提供有关其所见冲突的更多信息? (Microsoft编译器无需投诉就接受了此代码。)

Trying to compile the Python interpreter with clang (on Windows), I'm getting (after some refinement):

c:\Python-3.10.4\Python\pytime.c:603:5: error: conflicting types for '_PyTime_AsTimeval'
int _PyTime_AsTimeval(_PyTime_t t, struct timeval *tv, _PyTime_round_t round)
    ^
C:\Python-3.10.4\Include/cpython/pytime.h:126:5: note: previous declaration is here
int _PyTime_AsTimeval(_PyTime_t t, struct timeval *tv, _PyTime_round_t round);
    ^

Um... those don't look conflicting to me! What am I missing? Does the Python code do something unusual with these declarations? Is there a way to get clang to give more information about the conflict it sees? (The Microsoft compiler accepted this code with no complaint.)

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

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

发布评论

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

评论(1

Smile简单爱 2025-02-09 14:40:50

找到了!问题在于struct TimeVal在读取功能声明时尚未声明。 Microsoft C认为“结构的全局声明将即将到来”; Clang将其视为“暂时声明,然后将其丢弃,以使函数原型与以后的定义不相容”。

void square(struct foo *f);

struct foo {
  int x;
};

void square(struct foo *f) {}

并且可以通过在函数原型之前插入此内容来对其进行修补:

struct timeval;

我不知道哪种行为是否与标准的措辞更一致,但已将其报告为错误无论如何,以与微软编译器相同的方式行为的理论将是更有用的行为。

Found it! The problem is that struct timeval was not yet declared by the time the function declarations were read. Microsoft C takes that as meaning 'global declaration of the struct will be forthcoming'; clang takes it as 'make a temporary declaration, then discard it, so that the function prototype is incompatible with later definition'.

void square(struct foo *f);

struct foo {
  int x;
};

void square(struct foo *f) {}

And can be patched in pytime.h by inserting this before the function prototypes:

struct timeval;

I don't know which if either behavior is more consistent with the wording of the standard, but have reported it as a bug in clang anyway, on the theory that behaving the same way as the Microsoft compiler would be the more useful behavior.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文