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?
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.
Related
I'm trying to create a native library in C++, which I can use in Android.
I've created a project in Visual Studio 2017: Dynamic Shared Library (Android), and added my cpp code.
Though some of the code is running C++11, and I'd really like to keep it that way.
When I compile, I get the error:
This file requires compiler and library support for the ISO C++ 2011 standard.
This support is currently experimental, and must be enabled with the -std=c++11 or -std=gnu++11 compiler options.
So I first tried going to Project->Properties->C/C++->Language->C++ Language Standard, and set the options as following:
'
When I compile now, I get exactly the same error. So I tried manually adding the -std=c++11 flag under additional options, though still getting the error.
Why is the compiler not willing to compile using the ++11 standard, and what can I do to fix this? I know it's experimental, but it should at least try to compile.
Best regards
The problem was solved, when I changed the settings to be for All Platforms, and not just ARM.
I am new to coding and programming so please answer my question. Before i had "Have g++ follow the C++14 ISO C++ language standard [-std=c++14]" in my codeblock IDE. But last day i did a default reset in complier settings. After the reset "Have g++ follow the C++14 ISO C++ language standard [-std=c++14]" is not visible in the complier flags options. I tried re-installation of codeblock but it didnt work. how to reset codeblock to get the option back. Also what is the difference between ...std c++14 and ..std c++11.
The difference between c++11 and c++14 is minor.
Each one is a standard, which defines what c++ is. C++14 mostly extends C++11 with features, that didnt make it in time to c++11.
Its rather an extension to c++11, then a big jump in version like c++03 to c++11.
Using c++14 in Codeblocks must be done with the Compilerflags.
These must enable --std=c++14 -> The settings is not related to Codeblocks, but to the compiler that codeblocks uses.
I'm new to c++ & I've this big confusion around c++ & g++ versions. I've come to understand that there are different version of g++ compiler, latest being 4.8 (i think). But then I see c++98 & c++11 mentioned at so many places. Are these two versioning systems for the same thing or is it for totally different things? And if they are different, how can I check if I'm using c++98 or c++11? Thanks!
C++98 and C++11 are standards rather than compilers. They are issued by ISO and compilers are expected to implement the features as given in the standards.
The g++ compiler is one that provides (as of 4.8 anyway) most of the features from the c++11 standard, as you can see here.
This question already has answers here:
How to determine the version of the C++ standard used by the compiler?
(9 answers)
Closed 6 years ago.
Recently I had faced compiling errors in a c++ code I wrote so I've been asked if I was using a C++11 compiler, but honestly I don't know how to check on my compiler version ! so any idea how to figure this out ??
Btw I'm using codeblocks as an IDE which includes the GCC compiler and GDB debugger from MinGW. also if I'm compiling my c++ code under Linux what command should I run to know my compiler version ?
That can be a tricky question. C++11 refers to a version of the
standard, not to a version of the compiler. Different compilers, and
different versions of any given compiler, will typically implement a mix
of versions of the standard, at least for recent versions. More or
less, because any implementation of C++11 will be fairly new, and thus
probably fairly buggy.
Most compilers have options to output the version; many will output it
systematically in verbose mode. For g++, try g++ --version. Recent
versions of g++ do have some support for C++11, but you have to activate
it with -std=c++0x (rather than the usual -std=c++03 or
-std=c++98). As the name (c++0x, rather than c++11) indicates, it
is not truly C++11; it is an implementation of some (most?) of the
major new features, in a preliminary version based on various working
papers, and not the final standard.
(FWIW: I don't think any compiler fully implements all of C++11, but I'd
love to be proven wrong.)
You can find out your compiler version like this:
g++ --version
That doesn't tell you if you are using c++11. To use c++11 features, you would have to call the compiler with thr -std=c++0x flag:
g++ -std=c++0x ....
Bear in mind that gcc doesn't implement 100% of c++11 yet, and how much it implements depends on the version. See here for a table of supported features.
EDIT: strictly speaking, if you are using GCC you cannot be using a fully compliant c++11 compiler due to the missing features. But versions 4.6.1 onwards cover a great deal of the standard.
If you're in linux, checking the version is easy.
> gcc --version
Will tell you the version you have. Note that GCC C++11 support is incomplete still, you can find the details here: http://gcc.gnu.org/projects/cxx0x.html
I've used a few C++11 features myself, namely initializer lists, and the nullptr constant. I'm using GCC 4.6 and it's working fine.
edit: And yes, as #jaunchopanza said, you'll need the -std=c++0x compiler flag to make it work. If you're using Code::Blocks, just right-click on your project, choose Build options..., and check the item that says Have g++ follow the coming C++0x ISO C++ language standard [-std=c++0x]
I'd like to produce cross-compiler compatible C++ code.
I've produced a somewhat "exotic" code, that push the C++ language in its gray, weird, mysterious areas.
Considering my code only depends on boost and the STL, that the issue is to check code compatibility, and not lib compatibility:
Would my code compiling both msvc and Mingw ensures a 100% that my code is compatible with GCC on every platform?
Not at all.
Compiling your code with MSVC and MinGW guarantees that your code is compatible with Microsoft's C/C++ libraries. I understand you're only talking about code compatibility, but such a thing doesn't exist. If you're pushing C++ into the gray areas, it might well be that the same code will have different results depending on the platform you compile it on.
The best, and only way to guarantee full compatibility is compiling and testing it on both platforms.
Although using GCC with -std=c++0X -Wall -Wextra -pedantic (or any other std version) and getting rid of all the warnings will give a pretty good idea of code quality.
Honestly? To guarantee your code will compile with GCC on any platform is impossible. There is always that likelihood that something could be off, especially if you are doing 'exotic' things with your code.
You could also try compiling with cygwin, which would give a better idea of how it will build on a more Unix like system (although it's still not guaranteed to work on all systems, but it's better than just trying msvc and MingW which are both just windows compilers).