为什么 Clang 认为这些类型在开罗会发生冲突?

Why does Clang think these types in Cairo conflict?

我正在使用 Clang 从源代码构建 。我收到以下错误:

src/cairo-quartz-font.c:368:1: error: conflicting types for 'cairo_quartz_font_face_create_for_cgfont'
cairo_quartz_font_face_create_for_cgfont (CGFontRef font)
^

src/cairo-quartz-font.c:247:18: note: previous implicit declaration is here
*font_face = cairo_quartz_font_face_create_for_cgfont (cgFont);

但是,查看源代码,我发现这些定义:

247:

CGFontRef cgFont = NULL;
// ... 
*font_face = cairo_quartz_font_face_create_for_cgfont (cgFont);
CGFontRelease (cgFont);

368:

cairo_font_face_t *
cairo_quartz_font_face_create_for_cgfont (CGFontRef font)
{
    cairo_quartz_font_face_t *font_face;
    // ...

完整的来源是mirrored here

这里的类型冲突是什么?

当您在第 247 行使用函数 cairo_quartz_font_face_create_for_cgfont 时,它是未声明的(除非您未能使用 -Wall,否则您应该收到警告)。所以编译器填充了一个假定的return类型的int.

当你最终声明函数时,它的 return 类型不是 int。所以这是一个类型冲突。

通常这种问题可以通过 #include 使用函数原型 header 来避免。