a console application in C++

J

James Kanze

Right, just found that. So it seems that for C++ -ansi *is* actually
equivalent to -std=c++98.

At present. What will it mean when they also support
-std=c++03?
 
J

James Kanze

[...]
i want to create some console programme,

The problem is that the concept of a console program (as opposed
to some other type of program) is purely Windows. On most
systems, a program is a program, and C++ doesn't make any real
distinction.
 
L

Lionel B

]
Note: the "-std=c++98 -pedantic" flags ensure that you are compiling
according to the current C++ standard without any GCC-specific
extensions/ restrictions to the language.

Note that the "-std=c++98 -pedantic" flags only affect the compiler, and
do *not* ensure that you are not including non-standard headers or
linking against non-standard libraries.

No indeed, they only specify the *language* standard that the compiler
should respect.

[...]

To summarise: the only way to ensure that you are not including non-
standard headers or linking against non-standard libraries is ... don't
include non-standard headers and don't link against non-standard
libraries.
 
L

Lionel B

At present. What will it mean when they also support -std=c++03?

Who knows? Maybe then the g++ default will be -std=gnu++03' which will be
the same as -std=c++03 plus GNU extensions and if -ansi removes those
extensions you'll be left with -std=c++03?

Maybe they should have a flag -std=c++latest-supported (and then make
that the sodding default, rather than forcing you to mess about to get
standard behaviour).
 
J

James Kanze

Who knows? Maybe then the g++ default will be -std=gnu++03' which will be
the same as -std=c++03 plus GNU extensions and if -ansi removes those
extensions you'll be left with -std=c++03?

But perhaps for some older code, you'll still want -std=c++98.
I sort of suspect that this option was introduced for C, where
some people definitely only want C90, where as gcc tries to
support C99. The point is, you have a choice.
Maybe they should have a flag -std=c++latest-supported (and then make
that the sodding default, rather than forcing you to mess about to get
standard behaviour).

That sounds like a very good idea---why don't you propose it to
them. Adding a "-std=<lang>-latest" option sounds like a simple
and obvious improvement. With regards to the default: from what
I can tell, the C++ group are moving in the direction of
deprecating (and perhaps sometime eliminating) the GNU
extensions, so the number of extensions you get is going down.
What's really missing is:
-- that the option also affect the library, and
-- options for other standards, like Posix.
(I would expect that the default on a Unix machine also include
-std=posix<version>. Even when that contradicts -std=c++98.)
The problem with this is that on most platforms, the library, or
at least the C part of it) is beyond the reach of g++ itself.
The best the OS option could do is set the appropriate -D
options and (if necessary) the library path.
 
J

James Kanze

[...]
Note: the "-std=c++98 -pedantic" flags ensure that you are compiling
according to the current C++ standard without any GCC-specific
extensions/ restrictions to the language.
Note that the "-std=c++98 -pedantic" flags only affect the compiler, and
do *not* ensure that you are not including non-standard headers or
linking against non-standard libraries.
No indeed, they only specify the *language* standard that the compiler
should respect.

The "International Standard: Programming Languages -- C++",
ISO:IEC 14882 also defines what we traditionally would call a
library. From the point of view of the standard, the library is
part of the language (and is certainly part of the language
standard).
To summarise: the only way to ensure that you are not including non-
standard headers or linking against non-standard libraries is ... don't
include non-standard headers and don't link against non-standard
libraries.

Yup.

There are a lot of other bad practices that the compiler will
accept as well. (Things like indirectly returning a reference
to a local variable, for example.) Specifying "-std=c++98
-pendantic" is very useful. So are "-D_GLIBCXX_CONCEPT_CHECKS
-D_GLIBCXX_DEBUG -D_GLIBCXX_DEBUG_PEDANTIC". But you still need
good code review.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,995
Messages
2,570,230
Members
46,819
Latest member
masterdaster

Latest Threads

Top