![]() |
|
opinions on c++11 |
amarillion
Member #940
January 2001
![]() |
I've become intrigued with the possibilities of std::function and std::bind as a more flexible way to handle function pointers. It seems to require compiling with g++ -std=c++11 What's the general opinion of c++11 these days? Is the spec well supported? Do you use it or avoid it? Can I expect any issues with compiling on the less common platforms (I'm mainly thinking of android) -- |
bamccaig
Member #7,536
July 2006
![]() |
I haven't personally used C++11, but obviously the features it introduces are well received. It brings C++ a little bit closer to modern times. As for Android support, I have no idea. I'd imagine that you're going to run into issues if you need very portable code. You're best off investigating those yourself for specific use cases or probably avoiding the standard until you're sure all targeted platforms support it. -- acc.js | al4anim - Allegro 4 Animation library | Allegro 5 VS/NuGet Guide | Allegro.cc Mockup | Allegro.cc <code> Tag | Allegro 4 Timer Example (w/ Semaphores) | Allegro 5 "Winpkg" (MSVC readme) | Bambot | Blog | C++ STL Container Flowchart | Castopulence Software | Check Return Values | Derail? | Is This A Discussion? Flow Chart | Filesystem Hierarchy Standard | Clean Code Talks - Global State and Singletons | How To Use Header Files | GNU/Linux (Debian, Fedora, Gentoo) | rot (rot13, rot47, rotN) | Streaming |
SiegeLord
Member #7,827
October 2006
![]() |
The Android NDK ships with a pretty recent GCC, so you should be all set with C++11 support. C++11 itself is great, it revolutionized how you can write C++. Move semantics and closures turned out to be amazing additions. "For in much wisdom is much grief: and he that increases knowledge increases sorrow."-Ecclesiastes 1:18 |
Thomas Fjellstrom
Member #476
June 2000
![]() |
I've pretty much moved to C++11 for a lot of things. I like playing with templates, and C++11 makes them much more useful. Also std::thread is handy. -- |
beoran
Member #12,636
March 2011
|
OK, I'll be the curmudgeon here. I think C++ in general is a design disaster chock full of half baked yet overly complex features, badly grafted onto C. C++ 11 does add a few "interesting" features. Lambdas are nice to have in any high level language, and move semantics for a workaround for the inherent problems of templates, references and classes, which you wouldn't need at all, if you had real OOP like in Objective-C, but I digress. My experience with C++ has been invariably that once you start to us one of it's features you will need to use almost all of of it's features (use lambda's, now you need templates and classes too, etc), and then the accidental complexity will start hitting you badly. When you have to use C++ in a team, very often, people will try to use it in the most complex way possible because it makes them feel smart, which mean the code will become an unmaintainable mess of mostly wrappers around wrappers. Furthermore, C++ isn't even forward portable. I wrote my first game in C++ 2.0 (before even C++ 98) and now it doesn't even compile anymore. With C++ 11 now, everything you did in C++03 is obsolete and you're suppose to rewrite everything using the latest and greatest, that is, until we get to C++17 when you will have to rewrite again. Allegro does still compile because it's written in the far more conservative C, apart from the DirectX interface with is in a fairly limite d subset of C++ (just C + classes, essentially). For all these reasons I like to stick to plain C as much as I can, possibly enhanced with a scripting language. Another approach could be to use a severely restricted subset of C++ (like, say, Google does). Finally I don't want to start a debate on C++, just tell you of my experience. Yours might differ. I'd say, try it out and find it out for yourself. |
Thomas Fjellstrom
Member #476
June 2000
![]() |
beoran said: if you had real OOP like in Objective-C, but I digress. If you had ObjC, you'd also have horribly slow code Yes, C++ is complex. So is C when you get to scale, but to get to scale you have so much more boiler plate, and complexity to add manually. I used to be like you beoran. I was a staunch C supporter, and saw no point in C++ and its added complexity at all. Then I started writing something actually complex, took a look at my code and went "I'm re-implementing C++ features here... Why am I doing that?", then i went to learn C++ and haven't really looked back (sometimes I write C code for things). -- |
amarillion
Member #940
January 2001
![]() |
beoran said: I think C++ in general is a design disaster chock full of half baked yet overly complex features No disagreement here. I've played a bit with D too, and I like it much better. IMHO D strikes the right balance between language features and bare-to-the-metal. In work life I use Java and Groovy for everything, and D has some nice parallels with those languages. However, I'm sitting on a large pile of my own legacy code in C++, and I'm never going to find the time to rewrite it all in a different language. So my question really is - given that I'm using C++, should I make the leap to C++11? Forward compatibility is a problem - yes I had to fix a few things when adding -std=c++11, most notably clashes between boost and std namespaces. But given that I'm upgrading this code from allegro 4 to allegro 5, this was a small thing by comparison -- |
Thomas Fjellstrom
Member #476
June 2000
![]() |
I'd say jump. But maybe I'm a little biased. My way of learning C++11 was to write LuaGlue. It lets you bind C++ to lua with a minimum of fuss, and does it at compile time for the most part. Pretty light weight and speedy. I intend to go back to it later to rename, and clean it up somewhat. Right now, I'm working on a game engine (OMG!) for a game I've been planning and working on for a while. I certainly wouldn't want to use C for it. Ugh. That would be a massive headache. OT: Some people might ask why I'm writing my own engine. I've got two reasons, one I want to learn the lower level stuff, and two, I actually did some research into existing engines, and they did not seem to do what i wanted to do in a way that would actually make my life much easier in the long run. I also like writing lower level stuff... -- |
amarillion
Member #940
January 2001
![]() |
Thomas Fjellstrom said: I actually did some research into existing engines, and they did not seem to do I'd be interested to hear which engines you looked, and what your opinion is of them. -- |
Thomas Fjellstrom
Member #476
June 2000
![]() |
Well, I did some research, not a huge amount of in depth research. Looked into Unity, and whatnot, and while Unity is popular, it seems to have its issues with flexibility, especially when trying to do a voxel game. People mostly comment that once you get to a certain level in a game that isn't just a generic Unity like game, you end up having to start making serious customization to Unity, and that ends up getting messy. I imagine its the same with other engines, including the newly free'd quake engine. They were built for specific types of games in mind, and specific patterns. I may do some more research later for another game i want to do, but we'll see -- |
Erin Maus
Member #7,537
July 2006
![]() |
If you're using voxels or dynamic terrain of any kind, Unreal engine is not suitable if you want to use its collision/physics features. Collision data cannot be created during runtime. I just saved you about a minute of research. Since Unreal engine is essentially the biggest Unity competitor right now (and is open source + 'free' for some definition of free), I'd thought I'd mention it. For this work, I accept cash or check. My fair rate is hourly and equal to your country's GDP. Since it only took me 30 seconds at most to prepare the fact above, I will only charge 1/120th of my usual rate. Please note: if the check does not clear, then I will pursue legal action in the jurisdiction of my choosing. Thank you. --- |
Thomas Fjellstrom
Member #476
June 2000
![]() |
Aaron Bolyard said: For this work, I accept cash or check. You can have all my assets (and liabilities). but yeah, that's about what I came up with. The big engines just don't do dynamic. Dynamic is hard to do though, so I don't blame them. They were all written to do what they think are the most popular games, FPSs and other 3d first person things. you can shoehorn other types onto them, but you're asking for pain. -- |
RPG Hacker
Member #12,492
January 2011
![]() |
I personally love C++11 and will definitely make extensive use of it. I think by now the standard is old enough that all compilers of interest support it. Or rather, there is at least one compiler on all platforms of interest that supports C++11. "Platforms of interest" in my case are Windows, Linux and Mac, as well as possibly iOS and Android and - if I should ever even get that far - current gen platforms. Well, I'm not sure if PS4 and Wii U actually even support C++11, but I know that at least XBOX ONE supports, both, the STL and and C++11. I guess the other other two support C++11 code, too, but at least the Wii U doesn't seem to include the STL (I've searched for files including "namespace std" and got no hits). I think the Wii U only includes C libraries, anyways. Searching the PS4 SDK for "namespace std" got me several hits, though, so I suppose that one supports the STL as well. Just another hint at how outdated the Wii U is. It's by no means a bad system, but from my experience so far it's the least fun system to develop for, out of the three. Here is hope that this will improve for NX. Anyways, I'm getting off track here. My point is this: I'm fine with C++11, as long as I'm only sticking to code that is actually covered in the standard, since I don't care too much about supporting out-dated compilers and the code should at least work on all systems that adhere to the standard. C++11 just added so many features that should have been part of the standard for a long time, anyways. For example, as already mentioned in a thread from a few days ago, the possibility to directly set the encoding of string literals (u8"" for UTF-8, u"" for UTF-16 and U"" for UTF-32). Since this wasn't really covered by any standard before (as far as I know), it was just so unreliable to use string literals in the first place. I also like the many improvements done to the STL, like containers using allocator_traits, which allows you to use allocators with states. This is actually important for me, since I want to have full control over memory (this is especially important on consoles), yet I also want to be able to use different allocators in different situations, want to keep track of each of them separately and want to be able to create new memory allocator instances at run-time, which can't work when allocators are forced to use global states. These are just some of the things I appreciate about C++11. To be honest, I have only worked with it extensively for a few weeks now, so there are a lot of things I don't even know about C++11 yet, but so far, the more I learned about it, the more I appreciated it. Whatever problem I have in my engine, C++11 just always seems to have a solution for it. Thomas Fjellstrom said: Right now, I'm working on a game engine (OMG!) for a game I've been planning and working on for a while. I certainly wouldn't want to use C for it. Ugh. That would be a massive headache. OT: Some people might ask why I'm writing my own engine. I've got two reasons, one I want to learn the lower level stuff, and two, I actually did some research into existing engines, and they did not seem to do what i wanted to do in a way that would actually make my life much easier in the long run. I also like writing lower level stuff... I'm pretty much in the same situation right now. I've been working with Allegro 5 for several months this year, but first of all, I don't want to be stuck to Direct3D 9 or an out-dated OpenGL version forever. I eventually want to make an engine that runs in Direct3D 12 and Vulkan (with maybe adding D3D11 and OpenGL 4 ports later on for compatibility on older systems). Secondly, at some point, Allegro 5 just didn't really provide what I needed anymore. Allegro 5 was clearly written for 2D games with low to medium complexity in mind, with some neat new features that potentially allow for some more complex stuff (like shaders, vertex buffers etc.). However, I eventually got to a point where it really felt like Allegro lacked a lot of features I needed and where it felt like I always had to use a sledgehammer approach to get what I wanted. I still love Allegro, but I have gotten to a point where I need even more control over everything. Thirdly, having worked in professional game development for almost a year now, I have seen multiple engines and a lot of code that just gave me inspiration for my own engine, and I don't want to let that go to waste. That's why I eventually decided to write my own engine from scratch. It's only progressing slowly and it will probably take years before it actually gets somewhere (if I don't give up mid-way), but so far I'm still motivated, which is the most important thing for me. TL;DR: C++11, yay, making my own engine, yay!
|
beoran
Member #12,636
March 2011
|
Well, Thomas, on OOP, real oop is message passing and late binding, so C++ doesn't enable you to do that (QT does). Yes, real OOP is slower than using C++ style (simula style) classes but you loose flexibility. I see what you're getting at with the features of C++, as I stared using c++ with the same idea, but my opinion is opposite now. I was bured so baedly by C++ that now, I want to use C even if it means I have to implement some features that are already in C++. The fact that language has a feature is not the only reason to use it, at least, it isn't for me. The language has to feel right for me. Otherwise I could use Pygame or Godot or Blender game engine to make games and be done with it. I prefer C and Allegro because complete manual control is appealing to me. RPG Hacker, I was like you one day. I don't dislike C++ because I don't know it. I dislike it because I know it all too well. For me C++ turned sour once I used it extensively and in teams of either too mediocre or too clever programmers. But again, that's my personal experience. |
Chris Katko
Member #1,881
January 2002
![]() |
I see no reason to not use C++11 (or C++14) for any project of mine if I'm the sole or lead developer. It'd be like starting a new program with an old version of .NET. One warning though is that C++14 (and maybe... c++11?) in GCC is actually slower to compile since the new features have not been optimized yet. And a few features are actually not supported... which I found out the hard way with something pertaining to threads. I'm super excited to start playing around with std::future, std::promise, etc. -----sig: |
Polybios
Member #12,293
October 2010
|
Apart from the "major" features already mentioned, I also found some of the minor features of C++ 11 to be very convenient. For example, you can produce code that is far more readable when you can use auto to declare an iterator. Or when you can use the new foreach loop to iterate over a container. I also like the extended initializer-lists, the ability to wrap an array in std::array so it knows about its size, and std::to_string. Those minor features mitigate some of the awkward clumsiness of previous C++. Also, std::unordered_map, std::unordered_set have finally made it into standard STL... |
RPG Hacker
Member #12,492
January 2011
![]() |
beoran said: RPG Hacker, I was like you one day. I don't dislike C++ because I don't know it. I dislike it because I know it all too well. For me C++ turned sour once I used it extensively and in teams of either too mediocre or too clever programmers. But again, that's my personal experience. Well, I was referring to C++11 specifically. I have used C++ for a lot longer (several years by now, but especially extensively for the past year). I understand what you mean, though. C++ can indeed become a nightmare, depending on how it is used. I am currently working on a project where that is the case to at least some extent. It's a port of a last-gen title and the code at some places is just pure chaos. It has a lot of what you already described in a previous post, "wrappers of wrappers". Like, you try to figure out where a certain function is called in the code, but then you find out there is a wrapper function which does nothing but calling this function, so you have to consider that function as well. But then there is another wrapper for THIS function, so you get a nested construction that, at some point, gets so complex that you just have no idea anymore what happens where. I do agree that C++ in general has many problems and dangers, but for me, the benefits have always outweighed these.
|
LennyLen
Member #5,313
December 2004
![]() |
beoran said: I want to use C even if it means I have to implement some features that are already in C++. How about compiling your C code as C++ and just using the one or two C++ features you need without having to write them yourself?
|
beoran
Member #12,636
March 2011
|
My C code doesn't compile as C++. For example, for some reason Stoustrup didn't and still doesn't understand that void* is supposed to be a generic pointer, as in, "you can store anything in it without a cast". For the rest, The few features I need are normally filled in by libraries like bstrlib, kthash, etc. |
amarillion
Member #940
January 2001
![]() |
Polybios said: I've been compiling my project with C++ 11 enabled on Linux, Windows (MinGW) and OS X (clang) for a while now. No problems so far.
Sounds good. So far I've tipped my toes in the water, now I can go for a swim -- |
Thomas Fjellstrom
Member #476
June 2000
![]() |
beoran said: For example, for some reason Stoustrup didn't and still doesn't understand that void* is supposed to be a generic pointer, as in, "you can store anything in it without a cast". C doesn't like that either. -- |
beoran
Member #12,636
March 2011
|
No, that's a common misunderstanding about C, actually. In C, any pointer can be implicitly converted to void * and vice versa, no casts needed. From the ANSI C89 standard: Quote: 3.2.2.3 Pointers A pointer to void may be converted to or from a pointer to any
|
Thomas Fjellstrom
Member #476
June 2000
![]() |
Right, but Who uses strict C89 anymore? or old C compilers? If you do anything particularly interesting with void pointers, compilers are a lot more strict these days. -- |
Arthur Kalliokoski
Second in Command
February 2005
![]() |
1#include <stdio.h>
2
3int main(void)
4{
5 void *p;
6 void *q;
7 int *r;
8 int a = 43;
9
10 p = &a;
11 r = p;
12 q = r;
13
14 /*
15 printf("Value of a is %d\n",(int *)*p);
16 printf("Value of a is %d\n",(int *)*q);
17 */
18 printf("Value of a is %d\n",*r);
19
20 return 0;
21}
gcc -s -O2 -Wall t.c -o t t.c:6:8: warning: variable 'q' set but not used [-Wunused-but-set-variable] void *q; Output was: Value of a is 43 GCC 4.8.2 It wouldn't let me use the void pointers in the printf's, that's why I commented them out, but otherwise it's fine. They all watch too much MSNBC... they get ideas. |
Thomas Fjellstrom
Member #476
June 2000
![]() |
Arthur Kalliokoski said: It wouldn't let me use the void pointers in the printf's, that's why I commented them out, but otherwise it's fine. Just move the deref to before the cast, should work. -- |
|
|