[英]Is the expression “a==1 ? 1 : 0” with comparison plus ternary operator expression atomic?
[英]Ternary operator without the middle expression
我最近意識到你可以在GCC中使用三元運算符而沒有中間( ?:
或? :
works)並且它會將第一個表達式插入到中間:
// outputs 2
cout << (2 ?: 4);
// outputs 3
cout << (0 ? : 3);
這個標准在哪里? 我看了,沒看到任何關於它的事。
這是不是在標准可言 。
您所觀察到的是GCC擴展: https : //gcc.gnu.org/onlinedocs/gcc/Conditionals.html
如果省略它,則其值將從上下文轉換為bool
之前的第一個操作數中獲取。
擴展值在於不重復副作用並減少源代碼大小。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.