Managed/Native Debugging in C#/C++

I had a problem debugging my solution consisting of C#, C++/CLI, and native C++ projects. I was not able to get breakpoints working in the native C++ parts – after running the solution with breakpoints set, they were turning gray with warning sign, and their tooltip stated that “The breakpoint will not currently be hit. No symbols have been loaded for this document.” despite all debug properties were set right on those projects and all debugging symbols existed. After fighting it for a few hours and almost giving up, I started to think that the problem might not be with the native C++ projects, but rather somewhere else, e.g. in the StartUp project, which is C#. Checked that project’s properties, and guess what! Debug > Enable unmanged code debugging option was off!!! Switched it on, and voila – breakpoints work fine in native C++ DLL now!!! :)

Exceptions in C++

In Google C++ Style Guide they state that they are not using exceptions in C++ code at Google. They have reasons for it (“historical” mostly, as usual), but I do not necessarily agree with their view on it. Anyway, exceptions are quite a controversial topic in C++ community, and a must-read C++ Exceptions: Pros and Cons article at CodeProject goes deeper into the subject.

Personally I think that exceptions are really great, although I see how people can get things messy/wrong when using exceptions in inappropriate contexts and/or in inappropriate ways. Recipe to avoid problems? My own short list:

Security: Banned C Functions

memcpy() Is Going to Be Banned article at InfoQ talks about dangers of memcpy (and other memory/string related functions). Microsoft has more in-depth explanations as well as the list of Security Development Lifecycle (SDL) Banned Function Calls at MSDN. Also available from Microsoft is banned.h header file that, once included, will produce warnings for all the banned functions. Alternatively one can use the /W4-C4996 compiler option.

Win32/C++ Resources

A “healthy set” of Win32 and C++-related links (related stuff, anyway):

“Bit Twiddling”

Needed to do some “weird” things recently that involved bit operations, e.g. to create masks with certain number of bits set. During my “research” I found few interesting places:

More C++ Idioms

More C++ Idioms is a Wikibook aimed toward anyone with an intermediate level of knowledge in C++ and supported language paradigms. The goal there is to first build an exhaustive catalog of modern C++ idioms, and later evolve it into an idiom language, just like a pattern language.

The thing has been started by the author of C++ Truths blog. The blog is interesting by itself, as it has really many interesting articles on advanced C++ topics.

More C++ Resources

Michael D. Crawford’s GoingWare’s Bag of Programming Tricks contains wealth of super-interesting and useful information about many things, including advanced C++ topics. Especially I would mention Sermon at the Soup Kitchen (On C++ Software Quality and Institutional Resistance to Change), Pointers, References and Values (Passing Parameters, Returning Results, and Storing Member Variables with Musings on Good C++ Style), On Refactoring C++ Code (Properly managing memory returned by transcode() in the Xerces XML Library: from memory leak to clean, leak-free exception safety), and Pointers to C++ Member Functions (A tutorial on a useful yet poorly understood language feature, useful as a cache or to enable a different sort of polymorphism).

Then, there are tens of extremely interesting articles (despite older) about advanced C++ topics on Articles by Angelika Langer & Klaus Kreft site. Areas covered include STL, Standard Library, Core C++, and IOStreams.

Today’s Links

These are mostly related to systems’ programming:

Visual C++ 2008 Feature Pack

Microsoft has released Visual C++ 2008 Feature Pack already in April, but I somehow did not try it then and completely forgot about it. The pack features a number of MFC improvements, and also includes an implementation of TR1, portions of which are scheduled for adoption in the upcoming C++0x standard. TR1 includes a number of important features such as: smart pointers, regular expression parsing, new containers (tuple, array, unordered set, etc.), sophisticated random number generators, polymorphic function wrappers, type traits, etc.

Beef Up Windows Apps with the Visual C++ 2008 Feature Pack article in May 2008 issue of MSDN Magazine has a bit more information about the pack.

googletest: Another C++ Testing Framework

Just few days ago I found WinUnit, and voilaz – here is googletest, Google’s xUnit-based multiplatform framework for writing C++ tests. Supports automatic test discovery, a rich set of assertions, user-defined assertions, death tests, fatal and non-fatal failures, various options for running the tests, and XML test report generation.