问题标签 [comma-operator]
For questions regarding programming in ECMAScript (JavaScript/JS) and its various dialects/implementations (excluding ActionScript). Note JavaScript is NOT the same as Java! Please include all relevant tags on your question; e.g., [node.js], [jquery], [json], [reactjs], [angular], [ember.js], [vue.js], [typescript], [svelte], etc.
c++ - 逻辑 OR 和逗号运算符是否等效?
今天我发现了一个我以前从未见过的语法。||
和,
一样吗?
从这个程序的输出来看,似乎是这样:
它们是完全相同的东西还是有什么细微的差别?
c++ - 全局服务注册和逗号运算符
有一个注册服务的全局函数:
然后在 .cpp 文件的某个地方,一些服务会自行注册:
为什么不简单地通过调用 libecap::RegisterService(new Adapter::Service) 进行注册?它看起来更奇怪,因为没有使用全局变量Registered。
c - 循环和 if-else 中的逗号与 && 运算符
考虑代码:
现在,如果我将if
语句替换为if(x = a/b && a % b)
. 然后它也有效。所以我想知道用&&
运算符替换逗号,反之亦然if-else and loops
c - 用逗号分隔的 for 循环内的语句从左到右求值
这两个代码一样吗?for 循环中的这些语句写在同一行中,用逗号分隔。他们会从左到右进行评估吗?
另外我想问一下我可以在for循环中使用尽可能多的语句,用逗号分隔。像 for(i=0, j=0, k=0; .......) 一样吗?
和
c - 当 for 循环的条件部分中有多个以逗号分隔的表达式时会发生什么?
我这里有一个无限循环,但为什么呢?
c - How does for(i=0; i<5; x=(i++,a++)) work
I can't understand how this works and why it produces the following output.
this give as output:
c++ - 是否应该对没有副作用的丢弃值表达式进行诊断?
经过相当长的调试时间后,我发现我的代码中有一个错误,归结为这样的事情,我感到很愚蠢:
表达式的(p1, p2, color)
计算结果是它的最后一个操作数,但是编译器应该以某种方式保护我吗?(Visual Studio 什么也没说)
是的,你猜对了,我想调用一个绘图函数:Draw(p1, p2, color)
c++ - 如何在switch case中使用多个值
我的程序是
我得到了输出The number is 20
。我需要知道它是如何工作的,你能解释一下。谢谢。
c - Why does this use of comma work in a expression but fail in a declaration?
Am from high level OOP languages C# and Java and recently started scratching my head in C. I feel C a bit weird as equally as one feels JS is. So want to clarify below:
Below gives error and that seems intuitive as it looks like incorrect syntax even in OOP languages
However below works surprisingly:
Why is this behavior? Is their any significance to keep such behavior or just some parsing technicalities?
c++ - 为什么未计算的操作数内的包扩展会导致最后一个元素?
我可以在里面这样做decltype()
:
但不是这个:
它失败了,因为内部出现了包扩展,decltype()
但我认为包扩展会导致逗号分隔的参数列表。所以返回类型g(a, b, c)
将decltype(c)
取决于逗号运算符的工作方式(它返回最后一个元素)。当您在函数参数列表、模板参数列表、初始化程序列表等内部展开时,它会起作用。但为什么不是这样呢?