問題:
After reading Hidden Features and Dark Corners of C++/STL on comp.lang.c++.moderated
, I was completely surprised that the following snippet compiled and worked in both Visual Studio 2008 and G++ 4.4.在comp.lang.c++.moderated
上閱讀C++/STL 的隱藏功能和comp.lang.c++.moderated
,我完全驚訝於以下代碼段在 Visual Studio 2008 和 G++ 4.4 中編譯和運行。
Here's the code:這是代碼:
#include <stdio.h>
int main()
{
int x = 10;
while (x --> 0) // x goes to 0
{
printf("%d ", x);
}
}
Output:輸出:
9 8 7 6 5 4 3 2 1 0
I'd assume this is C, since it works in GCC as well.我認爲這是 C,因爲它也適用於 GCC。 Where is this defined in the standard, and where has it come from?這在標準中在哪裏定義,它來自哪裏?
解決方案:
參考一: https://stackoom.com/question/6tAK參考二: What is the “-->” operator in C/C++?