Eclipse CDT项目默认C++标准是什么?(CDT 3.8.1+GCC 8.6.0)
Let's get to the bottom of this—great question about verifying your default C++ standard, especially since Eclipse CDT's UI isn't making it obvious here.
First, Understand the Core Behavior
Eclipse CDT doesn't set a default C++ standard on its own; it relies on the GCC cross-compiler's native default unless you manually add a -std= flag in your project's build settings. That said, GCC 8.x normally defaults to C17, so your observation that it's not C11 suggests either your cross-compiler was customized for legacy compatibility, or there's a hidden flag in Eclipse overriding it.
How to Get the Definitive Answer
There are two foolproof ways to confirm:
1. Ask the Compiler Directly
Open a terminal and run this command against your cross-compiler (replace your-cross-g++ with the actual path/name of your GCC cross-compiler's C++ frontend):
your-cross-g++ -dM -E -x c++ /dev/null | grep __cplusplus
The output will be a macro value that maps directly to the C++ standard:
199711L= C++98200305L= C++03201103L= C++11201402L= C++14201703L= C++17
This is the most reliable check because it bypasses Eclipse entirely and shows you exactly what the compiler uses by default.
2. Check Eclipse's Build Flags
Eclipse might be adding a hidden -std= flag without showing it in the language support UI. To verify:
- Right-click your project → Properties → C/C++ Build → Settings
- Go to the Tool Settings tab, expand your cross-compiler's C++ Compiler → Miscellaneous
- Look at the Other flags field. If you see a
-std=entry here, that's the standard being used. If not, Eclipse is using the compiler's native default.
Why -std=c++03 Works (Even If It's Not Listed)
You noticed Eclipse's language support page doesn't mention C++03, but adding the flag doesn't throw an error. That's totally normal:
- Eclipse CDT 3.8.1's UI only lists newer standards it explicitly supports for syntax highlighting and code analysis (C++11 and later), but it doesn't block valid compiler flags.
- GCC has supported C++03 since its release, so passing
-std=c++03will always work with GCC 8.6.0.
Is Your C++98 Guess Correct?
It's possible—especially if your cross-compiler was built for embedded systems where legacy compatibility is prioritized. The __cplusplus macro check will give you the exact answer, but if you're seeing behavior that doesn't align with C11 features (like auto type deduction not working), that's a strong hint it's a pre-C11 standard (either C98 or C03).
内容的提问来源于stack exchange,提问作者Rick D.

