Live data from Hacker News

C++ Language Quick Guide

viptechworld.blogspot.com

21–28 of 28 posts

Re: C++ Language Quick Guide

#21
This guide is so primitive that it cannot be called useful. It can possibly be harmful, though, to those who don't know the language well and use this guide as a sole source of information.

Re: C++ Language Quick Guide

#22
post #16

> C++ is a superset of C, and that virtually any legal C program is a legal C++ program. This is not true. One example, void* pointers are not automatically converted to "narrower" types in C++ as they are in C.

Syntactically, C++ is a superset of C though, right? I can't think of any C syntax that's not valid C++, but I'm not exactly am expert in either

C supports variable-length stack-allocated arrays, while C++ doesn't. So code like

    void f() {
        int x;
        scanf("%d", &x); // read from user
        int numbers[x]; // dynamic
    }
is legal C, but not C++.

Also, the C "restrict" keyword doesn't exist in C++ either. Add in C's looser typing rules regarding conversions, and C and C++ are basically sibling languages at this point. Their common ancestor language being K&R-era C.

Re: C++ Language Quick Guide

#23
post #16

Earlier quoted context omitted.

Syntactically, C++ is a superset of C though, right? I can't think of any C syntax that's not valid C++, but I'm not exactly am expert in either

C supports variable-length stack-allocated arrays, while C++ doesn't. So code like void f() { int x; scanf("%d", &x); // read from user int numbers[x]; // dynamic } is legal C, but not C++. Also, the C "restrict" keyword doesn't exist in C++ either. Add in C's looser typing rules regarding conversions, and C and C++ are basically sibling languages at this point. Their common ancestor language being K&R-era C.

> C supports variable-length stack-allocated arrays, while C++ doesn't. So > code like > > void f() { > int x; > scanf("%d", &x); // read from user > int numbers[x]; // dynamic > }

I just pasted this in a file (and added `#include `) and compiled with g++, and it gave no errors or warnings and produced a *.o file, so maybe it does work?

Re: C++ Language Quick Guide

#24
post #16

Earlier quoted context omitted.

Syntactically, C++ is a superset of C though, right? I can't think of any C syntax that's not valid C++, but I'm not exactly am expert in either

> I can't think of any C syntax that's not valid C++, enum toto { a = 1 }; enum toto b = 1; Fixing versions of both standards could bring in more examples (like trailing comma in enums and use of the names reserved in C++, by the C code). Overall, ironically, as typing is stronger in C++ (which I agree is a non-syntactic change), poor C code (using lots of unjustified casts), will require less modifications to be com…

Thanks for the example!

Re: C++ Language Quick Guide

#25
post #23

Earlier quoted context omitted.

C supports variable-length stack-allocated arrays, while C++ doesn't. So code like void f() { int x; scanf("%d", &x); // read from user int numbers[x]; // dynamic } is legal C, but not C++. Also, the C "restrict" keyword doesn't exist in C++ either. Add in C's looser typing rules regarding conversions, and C and C++ are basically sibling languages at this point. Their common ancestor language being K&R-era C.

> C supports variable-length stack-allocated arrays, while C++ doesn't. So > code like > > void f() { > int x; > scanf("%d", &x); // read from user > int numbers[x]; // dynamic > } I just pasted this in a file (and added `#include `) and compiled with g++, and it gave no errors or warnings and produced a *.o file, so maybe it does work?

That's because gcc supports it as an extension to C++. It's not an official part of the language, and using it in C++ code is therefore not portable across compilers/platforms.

Re: C++ Language Quick Guide

#26
post #23

Earlier quoted context omitted.

> C supports variable-length stack-allocated arrays, while C++ doesn't. So > code like > > void f() { > int x; > scanf("%d", &x); // read from user > int numbers[x]; // dynamic > } I just pasted this in a file (and added `#include `) and compiled with g++, and it gave no errors or warnings and produced a *.o file, so maybe it does work?

That's because gcc supports it as an extension to C++. It's not an official part of the language, and using it in C++ code is therefore not portable across compilers/platforms.

clang++ seems to work as well. I don't have a Windows machine handy to try MSVC, though

Re: C++ Language Quick Guide

#27
Does this guide have anything about references? Didn't find anything about that, but maybe I missed it, I think its a pretty important topic to cover. Also didn't see anything about the different types of constructors.

Re: C++ Language Quick Guide

#28

Earlier quoted context omitted.

That does disqualify C++ as the __superset__ of C doesn't it?

I offer you the infamous phrase "extended superset" made famous in the world of SQL databases :). (Of course, you're right.)

Ugh, flubbed that: "extended subset". Sorry about that.
Post reply on HN