Skip to content

Instantly share code, notes, and snippets.

@YukiSakamoto
Created March 14, 2022 07:39
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save YukiSakamoto/24fb1a28bab036da39c18fb1d97ba77d to your computer and use it in GitHub Desktop.
Save YukiSakamoto/24fb1a28bab036da39c18fb1d97ba77d to your computer and use it in GitHub Desktop.
The order of the arguments evaluation in C++
#include <cstdio>
void func(int a, int b, int c) {
std::printf("%d %d %d\n", a, b, c);
}
int main(void)
{
int i = 0;
func(i++, i++, i++);
return 0;
}
@YukiSakamoto
Copy link
Author

clang on Macの場合

 ./a.out
0 1 2

関数の引数の左側から評価していく(ただし、fastcallしているのか、stackで引数を渡しているのかは不明)

gcc 4.8.5

./a.out
2 1 0

引数をスタックに載せる順序を考慮するとこちらの方が自然かな

gcc 4.8.5 (O3オプション使用)

./a.out
2 1 0

icc 19.0.5.281(gcc version 4.8.5 互換)

./a.out
0 1 2

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment