C++11 Compiler?!

Hello everyone!

I was reading in the cplusplus forum just now the following code:

1
2
3
4
5
6
7
#include <vector>
using namespace std;

int (main){

 vector<double> v3 = {1,2,3,4,5}; // v3 contains {1,2,3,4,5}
}


The thread was asking why the could produced compilation errors. Turns out that the guy wasn't using a C++11 compiler. Now, I want to ask this:

How can something "obscene" still be considered C++? I mean, if you want to introduce funny changes in the syntax, why not create a new language and call it subjective-C++ or whatever?

And, if each compiler writer wants to have his own rules, might aw well not refer to the language as C++ in the first place!
"obscene"? Is this also obscene?

 
int array[5] = {1,2,3,4,5};
No, but that is an old C declaration. Probably I should have picked another word. But the thing is that much of the syntax I'm using turns out to be compiler and IDE dependent.
Last edited on
@ToniAz
If vectors are meant to act be arrays but better, why not allow them to at least be initialized in the same way as an array?

Edit: C++11 isn't a new language, its still C++ just with new extensions added, nothing AFAIK has been removed.
Last edited on
closed account (o1vk4iN6)
Why would such a small change require a new language to be created ? Think how ridiculous it would sound if someone told you that C++ was created simply to add new syntax for initializing an array in C. Imagine how many variations of C there would be just adding one insignificant feature, I believe this was a problem with C++ before it became standardized.
Last edited on
@ToniAz:

All languages evolve over time. C++ has undergone tons of changes since its conception. So has C. Python, Java, C#... they all get updated every once in a while. C++ is no different.

I don't know if you've ever seen some old C code, but some of it looked kind of like this:

1
2
3
4
5
6
func(foo, bar)
int foo;
int bar;
{
  return foo + bar;
}


That might be considered "obscene" by your standards... but it's just the language's history. It evolves.
No, but that is an old C declaration. Probably I should have picked another word. But the thing is that much of the syntax I'm using turns out to be compiler and IDE dependent.


Code is never dependant on a particular IDE, and compiler dependencies are only there when you use language features not mentioned/declared by the standard (or depend on compiler behavior the standard leaves implementation defined, but you shouldn't do that anyways).

C++11 isn't fully implemented by any compiler that I'm aware of, but all popular C++ compilers support rather large subsets of C++11. For instance, pretty much all of them support the additions to the standard library because they only changed relatively little compared to the ones mentioned in tr1 that has been around for years. I think it's completely safe to make the transition for hobbyists, and I would at least consider it for businesses as well.
Last edited on
@Disch

I don't know if you've ever seen some old C code, but some of it looked kind of like this:


1
2
3
4
5
6
func(foo, bar)
int foo;
int bar;
{
  return foo + bar;
}



I'm speechless :O


Thank you everyone. It's been cleared out now, but what I'm afraid of is that all of a sudden C++ changes to something else, just like C changed to C++. I don't think "changed" is the proper word, but still...
I Don't see how that declaration syntax is, in any way, in any form, any almost synonyme expression, "bad"! Imagine this:
vector<int> vec={3, 7, 1, 9, 2, 6, 5, 4, 8}
How would you do it with the old declaration syntax?
1
2
3
4
5
6
7
8
9
10
11
12
vector<int> vec;
for (i=0; i<10; i++)
{
       switch (i)
       {
             case 0:
             vec.push_pack(3);
             break;
             case 1:
             //etc...
             }
       }

Do you see why they did it?
There's nothing at all stopping you coding in C++ 03 and instructing your compiler to compile for C++ 03.
@viliml, that example is a little exaggerated. C++03 vectors can be initialized easier than that:

1
2
static const int init[9] = {3,7,1,9,2,6,5,4,8};
vector<int> vec( init, init+9 );


Though I agree that is not ideal, and the new C++11 syntax is much better.
Last edited on
@Disch:
firedraco wrote:
"obscene"? Is this also obscene?
int array[5] = {1,2,3,4,5};
ToniAz wrote:
No, but that is an old C declaration.

So, according to him, It's not C++ and shouldn't be used!
Topic archived. No new replies allowed.