On 04/10/2019 15:08, Frederick Gotham wrote:
>
> I now write the entry point to my C++ programs like this:
>
> auto main(void) -> int
> {
>
> }
>
> auto main(int argc, char **argv) -> int
> {
>
> }
>
> for two reasons:
>
> (1) I know it won't go through a C compiler
I know my C++ code doesn't go through a C compiler because I use a C++
compiler to compile it.
If I were writing code that could be compiled as C or C++, and which I
was spreading around to people who don't have control of their build
processes, but I want to be sure it is never compiled as C, I'd add:
#ifndef __cplusplus
#error This code must be compiled as C++
#endif
> (2) I know the compiler is C++11 or above
>
I know my code is compiled with the required standard because I specify
it on the command line, in my makefile.
The main reason I would care about the standard version is because I use
features from a particular standard version. I see no point in doing
this artificially - if it makes sense to use a C++11 feature in your
code, use it.
And if I really require specific checking (as there are some subtle
changes in the versions, with code being valid but with different
meanings in different C++ versions), then I'd write:
#if __cplusplus < 201103
#error This code requires C++11 or newer
#endif
Write what you mean, and give clear, obvious error messages so there is
no doubt what has happened when someone has trouble compiling the code.
You really don't want people to fail to compile the code just because
you have written "auto main(void) -> int" - they will not judge you kindly.