Posts
67
Comments
120
Trackbacks
0
C# to C++ – A Somewhat Short Guide

Last updated: 2012-02-14

This is a big post – over 12200 16600 words – and so I’ve decided to make it available as a PDF download, which you can get here:

http://www.bobtacoindustries.com/Content/Devs/CsToCpp-ASomewhatShortGuide.pdf

It has bookmarks for easier navigation along with a Table of Contents and page numbers.

I expect that I will revise this from time to time and welcome any suggestions, feedback, and (especially) corrections. If so I will update the Last updated field at the top and will create a revised PDF as well. I hope this proves useful.

Update: I realized when looking at stats the other day that this post was so big that it wasn’t going through to many people’s RSS feeds (including my own!). So I stripped out the text and have decided just to keep it as a PDF link.

Updates and Changes:

2012-02-14

New sections:

  • Namespaces
  • enums subheading under Fundamental types
  • Functions
  • A brief word on the volatile keyword
  • Casting values
  • nullptr subheading under Pointers
  • Lambda expressions

Significant changes:

  • Added discussion of cstdint header to Fundamental types
  • Touched up some language and added a brief note on “mixins” to Multiple inheritance
  • Added subheadings to C++ constructors; also revised its code sample
  • Added a note about non-string uses of the ‘char’ type to Strings

There were many other miscellaneous edits made. I incorporated much of the great feedback I’ve received in the comments. I did not end up moving the Pointers section this time but have not ruled it out either. I’m on the fence about it because, to me, modern C++ is all about clean, safe code with automatic storage duration objects and C++ Standard Library container types. Pointers are still a part of C++ and likely always will be. But I’m not convinced that they belong right up front. I need to re-read the document through from beginning to end before I make a decision on that, I guess.

Most of the things I wanted to add this time around are in the document now. I’m considering a section on multi-threading but that will have to wait for another update. Once VS11’s ranged for loop support is released, I’ll be adding a section on that. I would like to make the templates discussion a lot more in depth at some point but that’s something for another time.

The link above has not changed; the new version is there now and has subsumed the old one. I’ll be posting this as a new blog post as well so if you see it twice, that’s why.

posted on Thursday, February 2, 2012 8:45 AM Print
Comments
Gravatar
# re: C# to C++ – A Somewhat Short Guide
Bob
2/3/2012 12:40 PM
This is great info, thank you so much for compiling and sharing it.

I would suggest a better ordering of your topics however. You talk about pointers and references quite often but don't actually get to them until much later.
Gravatar
# re: C# to C++ – A Somewhat Short Guide
MikeBMcL
2/3/2012 1:27 PM
Thanks! I'll work on re-ordering for the next version.
Gravatar
# re: C# to C++ – A Somewhat Short Guide
Morten
2/3/2012 5:43 PM
Thank you for sharing this. You ROCK!
Gravatar
# re: C# to C++ – A Somewhat Short Guide
Alejandro
2/4/2012 8:15 PM
Thanks a lot! This is likely what I needed...
Now, time for a very first "hello world" exercise :p.
Gravatar
# re: C# to C++ – A Somewhat Short Guide
Alf P. Steinbach
2/10/2012 8:03 PM
Great work! Some bugs though (posting for review on e.g. [comp.lang.c++] could be a good idea for later such works?). Anticipating that posting a comment here would not be trouble-free, I copied what I wrote over to Notepad before submitting. And well that I did! The submission apparently just disappeared into the Big Bit Bucket In The Sky, so I put it on Pastebin instead: http://pastebin.com/ZZEjgcTq
Gravatar
# re: C# to C++ – A Somewhat Short Guide
MikeBMcL
2/10/2012 8:13 PM
Alf: Thanks for the great feedback! I'm going to be readying the first update this weekend and I definitely appreciate the great suggestions and corrections!
Gravatar
# re: C# to C++ – A Somewhat Short Guide
Jayson Knight
2/11/2012 3:35 PM
Awesome reference materials in this article, thanks so much!
Gravatar
# re: C# to C++ – A Somewhat Short Guide
Sriivasa
2/12/2012 2:26 AM
Nice Artcle! Looking forward for more similar articles
Gravatar
# re: C# to C++ – A Somewhat Short Guide
Niklas Rother
2/15/2012 11:22 AM
Wow, exactly what I was looking for!
I wanted to learn a Bit C++l but didn't feel like taking One of these Books for absolute Beginners, because I knew C# already. Thanks!
Gravatar
# re: C# to C++ – A Somewhat Short Guide
MD
2/16/2012 11:16 AM
Just a quick note -- when you mention storage duration (and even before you warn against raw "new") it might be a good idea to emphasize that using automatic storage duration is the usual way of doing things in C++ and a good default choice. A common mistake of programmers transitioning from C# or Java is to (ab)use the "new" keyword for object(s) creation in cases where there's really no reason to use the free store.
So, chances are, that if a C# or Java programmer is thinking of typing:
SomeClass * object = new SomeClass; // don't do this if you don't need to
he should really be typing
SomeClass object; // do this

Generally, free store allocation is expensive compared to the stack-stored automatic variables, so it should be avoided whenever possible (and, as you mentioned, there's also the issue of memory leaks and having to use the smart ptrs.).

Regarding terminology, this might also be good to refer to: http://www.gotw.ca/gotw/009.htm

HTH!

Comments have been closed on this topic.
Bob Taco Industries is an ISV focused on game and app development for Microsoft platforms headed up by Michael B. McLaughlin. Mike is a Microsoft Visual C++ MVP (previously an XNA/DirectX MVP from 2011-2013), a developer, a writer, a consultant, and a retired lawyer. If you're a developer who is just getting started, consider checking out the BTI website's section for developers for links to code samples and other helpful sites.
Tag Cloud