Macos 正向参考(_telldir)
在MacOSX10.14的文件/usr/include/dirent.h中,我看到了这一行:Macos 正向参考(_telldir),macos,include,inline-assembly,forward-reference,Macos,Include,Inline Assembly,Forward Reference,在MacOSX10.14的文件/usr/include/dirent.h中,我看到了这一行: struct _telldir; /* forward reference */ 在同一文件中使用标识符: struct _telldir *__dd_td; include文件中没有其他地方定义telldir,但在同一文件中声明了函数telldir: long telldir(DIR *) __DARWIN_ALIAS_I(telldir); 我看到_DARWIN_ALIAS_I
struct _telldir; /* forward reference */
在同一文件中使用标识符:
struct _telldir *__dd_td;
include文件中没有其他地方定义telldir,但在同一文件中声明了函数telldir:
long telldir(DIR *) __DARWIN_ALIAS_I(telldir);
我看到_DARWIN_ALIAS_I宏定义为
#define __DARWIN_ALIAS_I(sym) __asm("_" __STRING(sym) __DARWIN_SUF_64_BIT_INO_T __DARWIN_SUF_UNIX03)**
我知道这是“内联汇编程序”,它定义了telldir,但我想知道更多关于这个定义的信息
提前感谢它并不像说明中那样完全是内联asm,它只是覆盖了符号名称的名称损坏。(例如,MacOS上的
static int foo
通常有一个符号名\u foo
。例如,在编译器asm输出中,您将有\u foo:.long 0
)
在GNUC中,intfooasm(“foobar”)
的asm符号名为foobar
,而不是默认的\u foo
。请看下面的答案:
如果你好奇的话,自己试穿一下
在本例中,我们有宏扩展的C预处理器字符串文字串联。e、 g
"_" "telldir" "_ino64"
在所有上下文中,包括在long telldir(DIR*dirp)asm(“telldir”)代码>
这个用例似乎是通过基于其他几个CPP宏设置名称来选择libc中的哪个telldir
实现。因此,如果\uuuuuu DARWIN\uu SUF\u64位INO\u T
被定义为“\uino64”
,\uuuuu DARWIN\u SUF\uunix03
被定义为空或/**/
,则这会将符号名设置为“\utelldir\uino64”
(不知道MacOS通常如何定义这些其他宏,但您显示的行的语法只是asm(“”
)中的字符串文字串联,用于设置符号名。)