Will code written under the C++98 standard work with newer compilers, such as g++. Or will it not work. Assumedly simple "Hello World" programs would work, but how about complicated command line programs?
Asked
Active
Viewed 664 times
0
-
Just read the list of incompatibilities at the ends of the C++03 and C++11 standards for an exhaustive list. – Seth Carnegie Feb 06 '13 at 23:33
-
The standard commission is really conservative about breaking compatibility with existing code, so this shouldn't be a major issue. – Matteo Italia Feb 06 '13 at 23:33
-
**In general**, no. For example: `int main() { auto int x = 0; }` is valid pre-C++11, because auto acted as a storage class specifier, but that's been removed since nobody actually used it. (And the `auto` keyword has been repurposed to do type deduction.) If your code actually *did* use it, it would break. – GManNickG Feb 06 '13 at 23:35
-
1The short answer is that old code will work in nearly every case. You can invent things that will break if you try hard enough, but even when you're trying it's not very easy to come up with many, and the few you do aren't likely to happen in real code. – Jerry Coffin Feb 06 '13 at 23:35
-
1A line I've heard frequently is that most of the breaking changes are of the flavour that "deserves to be broken". So even if it does break, fixing it will make your code better :-) – Kerrek SB Feb 06 '13 at 23:50
1 Answers
2
The -std=
command line argument to g++
allows you to compile against a specific version of the standard.
See: http://linux.die.net/man/1/g++
If in the future the authors of g++ (this applies to any compiler I suppose) decide to default to an incompatible version of the standard, this argument would let you compile older code.
It should only stop working if the authors of g++ drop C++98 support entirely. I see this happening only when the amount of C++98 code becomes so small or the new standards so incompatible with it that it's easier to have people update all their code than to keep supporting it. In any case, it should be a gradual and foreseeable change.

Vlad
- 18,195
- 4
- 41
- 71
-
Ok thank you, but that doesn't answer the question. This was more theoretical then anything. – MarJamRob Feb 06 '13 at 23:35
-
Note: I'm answering the question of whether C++98 can be compiled with newer compilers, rather than the compatibility of C++98 with newer standards. – Vlad Feb 06 '13 at 23:44