Port to C++
Hi, I've programmed a nice 2d game using the XNA framework, I'm want to try porting it to C++ just to try.
I never programmed using C++ so I'll checkig the syntax, but I'm afraid, because this is not easy as C# :(
Should I use directX or OpenGL OR anything else(prefered similar to the XNA Framework) ?
Thanks :)
Once you get started you will notice that C++ and C# are a lot similar than you think they are; the main difference is that you have to do a lot of stuff yourself that C# does for you (such as handling dynamic memory). As for a graphics API I suggest DirectX since XNA is basically a DirectX wrapper.
Quote:Original post by ant900
Once you get started you will notice that C++ and C# are a lot similar than you think they are; the main difference is that you have to do a lot of stuff yourself that C# does for you (such as handling dynamic memory).
No and no.
The only thing that C# and C++ really share are braces.*
Similarity: I don't know where to begin. I simply name a number of differences that I personally found extremely different and significant (partially annoying, partially amusing):
* C# has a giant library included (but before seriously arguing about that, have a decent look at the SC++L first)
* C# does not allow template metaprogramming
* C# does not allow to write const correct code
* C# does not have free functions (which I often consider clumsy)
Memory management: C++ allows you to do it manually, but you don't have to, think of smart pointers. Further (and this is quite important), in C# you usually use the new-operator all the time to just allocate the slightest class instance, whereas in C++ it is quite unusual to use new, in relation to code where you just declare variables. Let me give you an example, where the intent is to do stuff on local variables:
Bitmap bmp;using (GS gs = new GS ()) bmp = new Bitmap (gs.PdfToPng (filename, 1 + page, 360));List<Foo> foos = new List<Foo> ();for (int i=0; i<10; ++i) foos.Add (new Foo (new Bar()));
Ported to C++:
const Bitmap bmp (GS().PdfToPng(filename, 1 + page, 360));list<Foo> foos;for (int i=0; i<10; ++i) foos.push_back (Foo (Bar()));
* I am exaggerating a bit ;)
[Edited by - phresnel on October 30, 2009 6:05:52 AM]
Quote:Original post by phresnel
* C# does not allow metaprogramming
Err, C# doesn't allow template 'metaprogramming' as it doesn't have templates, but .NET's support for reflection, emitting bytecode, and compiling C# from C# absolutely destroy and put to shame, relatively speaking, C++'s paltry support for the same.
Quote:C# does not allow to write const correct code
At least not in the C++ way, enforced at compile time.
Thanks for the comments :)
I didn't understood: "C# does not allow to write const correct code"
I didn't understood: "C# does not allow to write const correct code"
Quote:Original post by MaulingMonkeyQuote:Original post by phresnel
* C# does not allow metaprogramming
Err, C# doesn't allow template 'metaprogramming' as it doesn't have templates
Missing word typo, mea culpa (corrected).
Quote:but .NET's support for reflection
Acknowledge. Though not on my personal "missing" list.
Quote:, emitting bytecode,
Not in the C++ standard library, but llvm (and some more) and every available compiler that is ABI compatible can be used to compile and run native massively optimized and adapted code. I name llvm specially, because you can invoke it it many ways, one of those being based on a graph, or you can directly write llvm-"assembly", or use on of the existing frontends.
Quote:and compiling C# from C#
You can also compile many languages from C++, and from C, and from Java, and from Basic. That is already obvious by the fact that compilers themselves are programs, not black boxes of magick.
The difference is that there is a compiler in the "standard runtime framework" in the C#-libraries(not in the core language C#, right?) (which I definitely consider a good thing), whereas in C++ it is not, but in that sense, it is optional by libraries.
Maybe I miss something, but apart from reflection, which is that something from your list that is not possible in C++?
Quote:destroy and put to shame, relatively speaking, C++'s paltry support for the same.
"Paltry" is trolling, "destroy" is straight preposterous, especially because you pointed out the distinctive nature of C++ templates and C# meta yourself.
But if you really think of "putting ashame and absolutely destroying paltries" (grrr, epic): How do you compute types, run algorithms, and emit code with null runtime cost in C#? Also, you may have missed that my list was about things ...
Quote:... that I personally found extremely different and significant... and not to compare (or "destroy") apples and oranges as you did.
Quote:Quote:C# does not allow to write const correct code
At least not in the C++ way, enforced at compile time.
Then when and how?
[Edited by - phresnel on October 30, 2009 9:30:17 AM]
Quote:Original post by Adir
Thanks for the comments :)
I didn't understood: "C# does not allow to write const correct code"
Marshall Cline has a good summary: Const correctness.
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement