I'm slightly afraid to learn C++ after being told so many horror stories. But for the low low price of free? Count me in.
C++ For C Programmers
11–20 of 53 posts
Re: C++ For C Programmers
#12Nice! However, I'd appreciate the converse more. I'm pretty well versed in C++, and every time I try to write something in C, I fall back to C++. I find memory management a pain without RAII, error handling a hassle without exceptions, and, well, anything really a pain without some sort of standard container library. I have the idea that there's good alternatives for these in C-land, but I'm unfamiliar with them and…
Re: C++ For C Programmers
#13Re: C++ For C Programmers
#14Re: C++ For C Programmers
#15I'm slightly afraid to learn C++ after being told so many horror stories. But for the low low price of free? Count me in.
If you want to learn a next generation language right now then you should look at Rust. It seriously has the ability to replace C++ in the long term. C++ will be remembered as the third dino besides Fortran and Cobol.
Re: C++ For C Programmers
#16C++ for C programmers: RUN
Re: C++ For C Programmers
#17Nice! However, I'd appreciate the converse more. I'm pretty well versed in C++, and every time I try to write something in C, I fall back to C++. I find memory management a pain without RAII, error handling a hassle without exceptions, and, well, anything really a pain without some sort of standard container library. I have the idea that there's good alternatives for these in C-land, but I'm unfamiliar with them and…
You're the first person i've heard of who falls back to C++, if that data point is of any value. AIUI exceptions and RAII are mutually exclusive in C++. I don't know enough about C++ so i wouldn't be surprised to find out this is wrong.
That is... very wrong. Exceptions are perilous unless you use RAII religiously (which you should; it's good.)
For more information, read up on RAII and search for "exception safety."
The definition of C++ RAII from Wikipedia: "In this language, if an exception is thrown, and proper exception handling is in place, the only code that will be executed for the current scope are the destructors of objects declared in that scope". Without this it is very hard to reap any benefits of exceptions (people have disagreements on what those are, if any, but that's another topic).
Re: C++ For C Programmers
#18Nice! However, I'd appreciate the converse more. I'm pretty well versed in C++, and every time I try to write something in C, I fall back to C++. I find memory management a pain without RAII, error handling a hassle without exceptions, and, well, anything really a pain without some sort of standard container library. I have the idea that there's good alternatives for these in C-land, but I'm unfamiliar with them and…
Re: C++ For C Programmers
#19Nice! However, I'd appreciate the converse more. I'm pretty well versed in C++, and every time I try to write something in C, I fall back to C++. I find memory management a pain without RAII, error handling a hassle without exceptions, and, well, anything really a pain without some sort of standard container library. I have the idea that there's good alternatives for these in C-land, but I'm unfamiliar with them and…
In C11 there is type generic macros that helps writing C++-like overloaded functions.
There are several extensions in GCC too.
For RAII-like memory management, there are __attribute__((constructor)) and __attribute__((destructor)).
C++ does type reflection on constant expressions via type traits templates, in GCC there is simply typeof().
If you are bored about writing static function modifiers, you can write a function inside function.
If you want to allocate a vector which won't change capacity and be released when out of local scope , for example in C++:
auto v = std::vector(n);
With C99 dynamic arrays you can use this instead: int v[n]; // n is a variable determined at runtime
You can use the union trick to achieve safer type casts too.Re: C++ For C Programmers
#20>Please use a modern browser with JavaScript enabled to use Coursera. One wonders how people who can't even create a static HTML page will manage to teach people a complex language like C++.