作者回复: 👍
作者回复: 我用海纳老师的代码分别在MacOS和ubuntu上编译运行了一下,结果很让我吃惊: macos上输出: 3 world!hello 而ubuntu上居然输出: 3 hello world! macos上的g++版本: $g++ -v Configured with: --prefix=/Library/Developer/CommandLineTools/usr --with-gxx-include-dir=/Library/Developer/CommandLineTools/SDKs/MacOSX10.14.sdk/usr/include/c++/4.2.1 Apple LLVM version 10.0.1 (clang-1001.0.46.4) Target: x86_64-apple-darwin18.7.0 Thread model: posix InstalledDir: /Library/Developer/CommandLineTools/usr/bin ubuntu上g++版本: gcc version 7.5.0 (Ubuntu 7.5.0-3ubuntu1~18.04) 按照代码语义,stack的先进后出,理论上:world! hello 应该才是对的。