简体   繁体   English

在哪些情况下 __sync_synchronize 会收到任何 arguments?

[英]In which cases does __sync_synchronize receive any arguments?

TheGCC documentation about __sync builtins lists __sync_synchronize as: GCC 文档关于 __sync 内置函数将__sync_synchronize列为:

__sync_synchronize (...)

This built-in function issues a full memory barrier.这个内置的 function 发出一个完整的 memory 屏障。

Which is meant to signify a variadic function (taking any number of arguments), but without a mandatory first argument, which is not even syntactically allowed in the C standard;这意味着表示可变参数 function(采用任意数量的参数),但没有强制的第一个参数,这在 C 标准中甚至在语法上都是不允许的; in any case, assuming it can run away with it because it's a compiler builtin, I'd like to know: is there any case at all in which this function receives arguments ?无论如何,假设它可以逃跑,因为它是一个内置的编译器,我想知道:这个function 是否会收到 arguments

The GCC documentation above explains why the ... are present:上面的 GCC 文档解释了为什么...存在:

All of the routines are described in the Intel documentation to take “an optional list of variables protected by the memory barrier”.英特尔文档中描述了所有例程,以采用“受 memory 屏障保护的变量的可选列表”。 It's not clear what is meant by that;目前尚不清楚这是什么意思。 it could mean that only the listed variables are protected, or it could mean a list of additional variables to be protected.这可能意味着只有列出的变量受到保护,或者可能意味着要保护的其他变量的列表。 The list is ignored by GCC which treats it as empty.该列表被 GCC 忽略,将其视为空。 GCC interprets an empty list as meaning that all globally accessible variables should be protected. GCC 将空列表解释为应保护所有全局可访问变量。

For a full memory barrier, it makes sense to write nothing inside.对于完整的 memory 屏障,在里面什么都不写是有意义的。

I tried googling for it (eg this website contains 30 usage examples ), looking at the Stack Overflow questions containing the builtin, and using Github's code search, and I couldn't find a single call of __sync_synchronize with arguments passed to it.我试着用谷歌搜索它(例如这个网站包含 30 个使用示例),查看包含内置函数的 Stack Overflow 问题,并使用 Github 的代码搜索,我找不到传递给它的__sync_synchronize的单个调用。

So, if I want to support the builtin in a tool, it seems I could simply treat it as if it were declared as __sync_synchronize(void) , and it would always work.因此,如果我想在工具中支持内置函数,似乎我可以简单地将其视为声明为__sync_synchronize(void) ,并且它总是可以工作的。

Is there a legitimate case where one might want to pass an argument to that builtin?是否存在一个合法的案例,可以将参数传递给该内置函数?

You have in a way self-answered.你在某种程度上已经自我回答了。 I think the bit of information you are missing is that builtins are not real functions and their arguments may not be passed anywhere or even evaluated.我认为您缺少的信息是内置函数不是真正的函数,它们的 arguments 可能不会在任何地方传递,甚至不会被评估。 The compiler will generate some code when you use it, but the builtin may not be a proper callable function.编译器在使用时会生成一些代码,但内置的可能不是正确的可调用 function。

Those are not arbitrary arguments, that was really supposed to be a list of variables (not, eg expressions).这些不是任意的 arguments,它实际上应该是一个变量列表(不是,例如表达式)。 Which may have had some mysterious function in an Intel compiler, but gcc will happily ignore.在英特尔编译器中可能有一些神秘的 function,但 gcc 会很乐意忽略。 gcc probably kept the same signature to maintain compatibility with some existing code. gcc 可能保留了相同的签名以保持与某些现有代码的兼容性。

Builtins may do strange stuff to their apparent arguments, like "Neither argument is evaluated."内置函数可能会对他们明显的 arguments 做一些奇怪的事情,比如“没有一个参数被评估”。 or "the built-in function does not evaluate the expression that is not chosen".或“内置 function 不会评估未选择的表达式”。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 __sync_synchronize 有什么作用? - What does __sync_synchronize do? GCC内存屏障__sync_synchronize vs asm volatile(“”:::“memory”) - GCC memory barrier __sync_synchronize vs asm volatile(“”: : :“memory”) 在哪些情况下 printf 返回负值? - In which cases does printf return a negative value? C 编译器不提供结束 null 值的情况有哪些? - What are the cases in which the C compiler does not provide an ending null value? 在哪些情况下alloca()有用吗? - In which cases is alloca() useful? 有什么方法可以限制在switch语句中出现的值? - Is there any way I can restrict the values which can be take as cases in a switch statement? 当您不想传递任何变量时,是否可以在C变量长度自变量函数中使用带格的情况? - Can you have in C variable length arguments functions with cases when you don't want to pass any variable? 命令行参数中某些情况下的输出错误 - Wrong output for certain cases in command line arguments 指向 args 结构的指针变化太快,因此线程没有收到正确的 arguments。我该如何解决这个问题? - Pointer to args struct changing too quickly, so thread does not receive correct arguments. How do I fix this? 是否可以实现不执行任何系统调用的C程序? - Is it possible implementing a C program which does not perform any system calls?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM