【问题标题】:When is: typedef __intn_t(__INTPTR_WIDTH__) intptr_t; legal? And, why?什么时候是:typedef __intn_t(__INTPTR_WIDTH__) intptr_t;合法的?而且,为什么?
【发布时间】:2016-02-14 23:31:05
【问题描述】:

我最近意识到我的 Mac(来自终端)上的“gcc”和“clang”正在 Xcode 目录中搜索简单的包含文件,例如
我发现当一些简单的有效程序(在 gcc/clang 下)无法使用 tcc(Tiny C)编译时,因为在 /usr/include 下找不到

一些搜索显示 gcc 和 clang 的行为好像有一个隐含的:

-I /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/../lib/clang/7.0.2/include 

而且,确实 stdarg.h 在该目录下。 (顺便说一句,我的 ENV 变量中没有任何东西有这样的路径。)

我提供了 tcc 的路径,但我的程序仍然没有编译,因为在 Xcode 的 stdint.h 中一个有趣的行上弹出了一个错误

/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/../lib/clang/7.0.2/include/stdint.h 有以下内容:

typedef  __intn_t(__INTPTR_WIDTH__)  intptr_t;

(并且“__INTPTR_WIDTH__”显然被编译器隐式定义为 -m64 下的 64 和 -m32 下的 32)。

但是,这似乎会扩展为:

typedef __intn_t(64)  intptr_t;

如果我用这样的一行尝试 clang 或 gcc,我会(如我所料)得到一个语法错误,就像我对 tcc 所做的那样。

如果有人能告诉我为什么/何时该行有效,我将不胜感激。

谢谢,

斯坦


cc -E fum.c(El Capitan,Apple LLVM 版本 7.0.2 (clang-700.1.81))

   # 1 "fum.c"
   # 1 "<built-in>" 1
   # 1 "<built-in>" 3
   # 325 "<built-in>" 3
   # 1 "<command line>" 1
   # 1 "<built-in>" 2
   # 1 "fum.c" 2
   # 1 "/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/../lib/clang/7.0.2/include/stdint.h" 1 3 4
   # 63 "/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/../lib/clang/7.0.2/include/stdint.h" 3 4
   # 1 "/usr/include/stdint.h" 1 3 4
   
   ...250 lines deleted, going in/out of stdint.h, finally dropping back to line 64 of the Xcode version...
   
   # 60 "/usr/include/stdint.h" 2 3 4
   # 64 "/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/../lib/clang/7.0.2/include/stdint.h" 2 3 4
   # 2 "fum.c" 2

(就是这样,fum.c 由一行组成:#include) (抱歉,这是一个 sn-p ...stackoverflow 拒绝了我所有尝试将代码粘贴到 ... 手动(4 个空白前缀)或单击“代码”按钮 ...不断出现删除换行符,重新格式化文本)。

【问题讨论】:

  • 似乎是clang之类的扩展。
  • 你能告诉我们cc -E file.c的输出,其中file.c只包含#include &lt;stdint.h&gt;吗?
  • __intn_t 是否在某处定义为宏?类似#define __intn_t(_N) __intn_t_(_N)#define __intn_t_(_N) int##_N##_t
  • @FUZxxl:stackoverflow 不允许我粘贴 870 个字符的评论,所以我将尝试编辑主要问题以将其添加到末尾。
  • @rici 好点。它是:#define __intn_t(n) __stdint_join3(int, n, _t)

标签: c xcode


【解决方案1】:

rici指出的问题答案,谢谢。 tcc 没有预定义 INTPTR_WIDTH,因此 __intn_t(n) 未能按预期扩展。

我没有看到“这回答了它”按钮,所以我点击了“这有帮助”。

谢谢!

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2018-08-22
    • 2016-05-06
    • 2011-08-09
    • 2012-02-28
    • 1970-01-01
    • 2015-08-31
    • 1970-01-01
    相关资源
    最近更新 更多