Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why does the -std=c++98 flag sometimes not work?

Tags:

c++

c++98

The situation is as follows:

I want to create a simple c++ program, but it has to use only C++98 functions.
I am using Ubuntu 20.04.4 LTS.
I am using c++ as compiler
I am using the following flags for compiling: -Wall -Werror -Wextra -std=c++98 -pedantic-errors

Now if I am using the function stoi() from <string>, compiling will fail, as expected, because stoi() is C++11, as you can see here.


But here comes the weird behavior that I am not able to understand:
using round or roundf from <cmath> won't trigger the -std=c++98 flag, even though, from what I can see here, all round functions are C++11.

Is there any good explanation why this is happening?


EDIT:
as jjramsey mentioned, there is the chance that the standard-C-function of round was used, so the -std=c++98 flag will have no effect on that. Can anyone confirm this theory?

like image 811
tblaase Avatar asked Oct 20 '25 04:10

tblaase


1 Answers

Nothing stopped a compiler from implementing anything pre-standard. For example, Visual Studio 2010 was not a standard C++11 compiler, yet implemented (to some extent) lambdas.

The only thing to expect from a C++98 flag is that all (hopefully) features of C++98 are implemented. Anything beyond that is just a pre-standard C++11/14/17, etc "bonus" that the compiler has implemented.

Of course, these bonuses were not official, and most were based on a draft of the future C++ standard. Once the C++ standard for 11/14/17, etc. came to be, a lot of those features introduced in those older compilers were either non-standard, didn't work properly, or missing.

like image 108
PaulMcKenzie Avatar answered Oct 21 '25 17:10

PaulMcKenzie



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!