원래 gcc 쓰다가 요 며칠 clang 써봤는데, 평가 순서가 다르더라?


unspecified긴 한데, 신기해서 써봄. 참고로 20기준임.


1)

#include <iostream> #include <string> auto vue(std::string x) -> std::string { std::cout << "vue " << x << 'n'; return x; } auto jue(std::string, std::string, std::string) -> void {} auto main() -> int { jue(vue("s"), vue("e"), vue("x")); return 0; }


[gcc]

vue x vue e vue s


[clang]

vue s vue e vue x


gcc가 뒤부터 평가하는건 대부분의 calling convention에서 거꾸로 넣기 때문(가변인자땜시)이라고 알고있는데,


clang은 그냥 앞부터 평가하더라...


참고로 파이썬은 앞부터 평가하고,


러스트는 표준에서 지정하고 있지는 않으나 rustc가 앞부터 평가함.



2)

#include <iostream> #include <string> auto vue(std::string x) -> std::string { std::cout << "vue " << x << 'n'; return x; } auto operator,(std::string lhs, std::string rhs) -> std::string { std::cout << "bobim " << lhs << ' ' << rhs << 'n'; return lhs + rhs; } auto main() -> int { vue("s"), vue("e"), vue("x"); return 0; }


[gcc]

vue x vue e vue s bobim s e bobim se x


[clang]

vue s vue e bobim s e vue x bobim se x


이건 모든 binary operator 공통사항임.


gcc는 일단 뒤부터 함수를 전부 호출하고 연산자를 차례로 호출하는데,


clang은 함수도 차례로 호출함.


clang 솔직히 컴파일이 더 빠르다던가, 바이너리가 gcc보다 구리다던가 이런건 별로 체감 안되는데, clangd는 확실히 좋더라 ㅇㅅㅇ