For a school assignment, I am required to use C++ version 03. I have a Mac, and I was told to use Xcode by my instructor.
After a bit of research, I found the place on where to change the version of C++ that is being used. As shown in the image, the version C++03 is not available. I tried typing "C++03 [-std=c++03]" in the "Other..." option, but my build failed.
I tried searching around on here and online, but I couldn't find anything that provided a solution.
Can someone please give me some guidance on what to do here? I am entirely new to C++, and I simply just want some help in being able to compile my code.
Thanks.
In Xcode on the Macintosh, to use C++03 (which should be nearly the same or identical with C++98), you can select the C++ Language Dialect > Other... > and type in c++03 (lowercase) in the field.
C++03 was more of a "big fix" to C++98, (q.v. this answer). It resolved some ambiguities in the language specification. Rather than being a significant new C++ standard.
You'll note that there are options like C++98 and GNU++98. The GNU++XX options enable several GNU extensions to the language, which if utilized means the code will not be strictly standard C++ compliant.
C++11 was a major change to the language. C++11 and later are sometimes referred to as "modern C++".
Related
I know those flags are for C++11 in Eclipse.
But I don't know what is difference and which one is more preferred.
It seems that they both are working with C++11 normally.
You should prefer -std=c++11.
(Note: I assume -std=c++11x is a typo in your question)
The old -std=c++0x is only needed for older compiler versions that did not support -std=c++11 and they chose that name to express the preliminary and unstable nature of features (and the ABI) of the then upcoming C++11 (and when it was still unclear whether that would eventually become C++10 or C++12). They changes some of the details adapting to the changing working drafts of the standard at the time before the C++11 standard was officially released.
If your compiler supports -std=c++11, there is no reason to use -std=c++0x. Concerning compatibility: There might even be differences and incompatibilities, but these are not just bound to the use of -std=c++0x, but to specific versions of the compiler. When the compiler supports both, they should be identical.
C++ and C Standards are usually named after the year they are published in, which makes it easier to remember by.
For example, in C++, the original Standard was published in 1998, so we talk about C++98, and when we refer to its first correction, published in 2003, we talk about C++03.
It had been purported that the next Standard after would be done for 2008, but since it was uncertain, it was dubbed C++0x, where the x stood for either 8 or 9. In practice though, as we all know, the planning shifted and so we end-up with C++11.
Still, for the next version (C++1x), Bjarne Stroustrup stated his intent to do it in 5 years (so about 2016). For now, there are changes envisionned to the core language (concepts, modules and garbage collection), and the focus seems to be more on extending the library (filesystem for example), but it's still early so who knows!
I just started to get my hands dirty with C/C++, and I am still getting my head around the different concepts (I've written mostly Java previously). I'd really like to know which C/C++ compiler is used and also which standard library is included. Also, I'd like to know where I can find the API documentation of the respective standard library (like the Java SE API docs).
For C++:
Xcode 4.6.2 uses the Clang C++ compiler frontend with LLVM as backend which is conform to the C++11 standart and uses libc++ as the standart library.
Here you can finde a apple presentation about libc++.
I'm not an XCode user, but it seems to be Apple's LLVM Compiler (by default) according to Apple's website: https://developer.apple.com/technologies/tools/. But, I guess, like any other IDE XCode does support other compilers like GCC. Also depends on your XCode version it seems: http://useyourloaf.com/blog/2011/03/21/compiler-options-in-xcode-gcc-or-llvm.html
Here's a question in SO that asks about the default compiler and the answer seems to have the code to find just that: In Xcode 4.5, what is "Compiler Default" for "C++ Standard Library" and "C++ Language Dialect"?
According to this post 4.6 uses clang instead of GCC for C++: http://cplusplusmusings.wordpress.com/2013/02/26/c-and-xcode-4-6/
P.S.: Googling does help ;)
I just noticed the second half of the question was never really answered:
... I'd like to know where I can find the API documentation of the
respective standard library ...
A simple Google search will reveal a wealth of information about this. Do note, however, that the "C++ Standard Library" is not the same thing as the "C Standard Library," so be careful of that when searching and reading. C++ has its roots in C, but the two have diverged to become separate languages that share a lot of commonality -- and a lot of hidden differences.
The canonical reference work regarding this is titled, appropriately enough, "The C++ Standard Library" by Nicolai M. Josuttis, published by Addison-Wesley. Many C++ programmers keep this on their bookshelves as a reference.
There is a good online reference for the library at https://cppreference.com/.
If you are interested in specifics of the LLVM implementation used by Apple's Xcode, see https://libcxx.llvm.org/ .
For a comprehensive list of the most highly recommended books and references for C++, Stack Overflow already has a very good FAQ regarding this: The Definitive C++ Book Guide and List.
Is there going to be a new version of C++ and when?
The creator of C++ C++0X FAQ:
http://www2.research.att.com/~bs/C++0xFAQ.html
Question: When will C++0x be a formal standard?
But C++ 0X does exists in some degree in various compilers. See both:
Question: When will compilers implement C++0x?
GCC C++ 0X support
To see what C++ 0X will be like, look at the wiki:
Wiki C++ 0X
The C++0x is the unofficial name for the new C++ Standard which is intended to replace C++03 standard (published in 2003). The final draft of the international standard is due in March of 2011. However this does not mean you will be able to use the new features straight away as the standards will have to be implemented by compilers and the completeness of these implementations will vary.
You can find a draft of the new standard here:
http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2010/n3092.pdf
However you can use the Technical Release 1 libraries which include a fair deal of functionality that will appear in the new standard which you can find here:
http://en.wikipedia.org/wiki/C%2B%2B_Technical_Report_1
If you are looking for the status of the C++ox implementation in GCC (which is a free compiler) see this link:
http://gcc.gnu.org/gcc-4.5/cxx0x_status.html
Here is a link to a really detailed FAQ that provides a lot of additional information:
http://www2.research.att.com/~bs/C++0xFAQ.html
However, the experience shows that the complete implementation of a freshly released standard, takes years... If one considers the complexity of the recent additions, I am very pessimistic about getting cross-platform compliant implementations soon.
I read that MSVC is not fully compilant to the ISO C++ standard (German Wikipedia and several Tech sites).
In which ways isn't C++ standards compilant?
Actually no compiler is fully standard compliant, but MSVC gained its reputation for implementing everything that the standard didn't explicitly state in a profoundly stupid and unportable way.
I would say that the latest releases are relatively good when it comes to standard support, at least when you try to compile standard compliant code in MSVC.
But MSVC is still very lazy when it comes to pointing out code, that doesn't follow C++ standard (even on the strictest settings), so porting code from MSVC to anything else is always huge pain.
But there are still many flaws/bugs/etc... for example unlike GCC, MSVC will allow you to modify a set/map iterator.
Well, I think it depends on your definition of compliant. There are several things that have not been implemented in the standard by almost any compiler company (several suggestion from the 98ish revision and template definitions in implementation files). MS has extended the language somewhat also. However, if you write code in basic c++ without the MS extensions or libraries, it will most likely be portable to another compiler with very, very minimal work (if any).
It's been a while since I've looked into this, but the C++ library that I work on uses quite a lot of template metaprogramming (nothing horribly complicated, but still beyond the simplest levels), and for quite a while it wouldn't compile under MSVC due to bugs or missing functionality in their template resolution code, although it works fine in GCC and Intel's C++ compiler.
I don't think we've tried it in the latest couple of revisions of MSVC, so they may have fixed those bugs.
Also, IIRC, MSVC does not turn on run-time type information support by default (for performance reasons), and support for that is required by the C++ standard.
Is anyone using the GCC 4.4.0 C++0x support in production? I'm thinking about using it with the latest MinGW, but I'm not sure if it's mature enough.
I'm interested in:
TR1 support
auto
initializer lists
IMHO, TR1 support and auto are safe to use. In the case of auto it was one of the first features to be included into the standard and is a relatively small change to the language. I would therefore have no problem using it.
I would be a bit more hesitant about using initializer lists. On some other forums (eg. comp.lang.c++.moderated) there are questions about their behaviour and its possible that they may change closer to the release of the standard.
I'm not using GCC 4.4.0 C++0x support in production but I'm using the TR1 features with the help of the Boost Library http://www.boost.org/.
The Boost Library is well tested and often used in production environments. If you convert to the C++0x standard later the only thing you have to do is changing your include Directives http://www.boost.org/doc/libs/1_40_0/doc/html/boost_tr1.html.
In my opinion it's currently better to use the Boost Library until the standard is finished. It's a much more compiler independent way.
MinGW simply won't compile with '-std=c++0x'. Strange enough, '-std=gnu++0x' works. Anyway it seems buggy and I won't count on it.