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!!! :)
Finally I am back! :) Last year or so I was really busy working on our product, but now we are basically ready, and I can spare more time for “hobbies”.
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:
- Use exceptions when they are really needed, i.e. when something exceptional happened
- Understand Exception guarantees AKA Abrahams guarantees (see more at Exception-Safety in Generic Components – Lessons Learned from Specifying Exception-Safety for the C++ Standard Library by David Abrahams)
- Follow Resource Acquisition Is Initialization AKA Resource Initialization Is Acquisition (or RAII/RIIA in short) principle
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.
A “healthy set” of Win32 and C++-related links (related stuff, anyway):
- MVP Tips, Techniques, and Goodies by Joseph M. Newcomer has a lot of C++ and Win32 topics, covering all “gray” areas like asynchronous operations, synchronization, threading, memory leaks, optimizations, various Windows APIs, device drivers, etc. For example, there is An introduction to memory damage problems that goes thoroughly through the topic, or absolutely fantastic The n Habits of Highly Defective Windows Applications that nicely enumerates ugliest “no-no’s” one should avoid in his code if he wants to sleep well :)
- C++ In Action, book by Bartosz Milewski. Cool thing is that there is a web edition of the book. Additionally, on the C++ Resources page there is Windows API Tutorial, RSWL: Free Windows Library, and some other papers and presentations, including topics on Resource Management, something called auto_vector ;) , and rather interesting Dealing with Software Complexity presentation.
- Win32 samples has a lot of samples for Net*() APIs, as well as for LSA, NTFS streams, processes, security
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:
- Bit Twiddling Hacks – lots of snippets related to bit operations, e.g. counting, reversing, swapping, interleaving, testing, etc., etc., etc.
- Creating multiple numbers with certain number of bits set – this was the answer to my need, clean and simple
- Technical Interview Questions – has a lot of interesting topics, nicely categorized, although not all-encompassing, if comparing to the first link above
The C++ Source is a great online jounal for the C++ community (you will find Bjarne Stroustrup and Scott Meyers among its contributors).
In The Most Important C++ Books…Ever, Scott Meyers (yes! the one!) shares his picks for the five most important books in the history of C++, along with why he chose them. Similarly, in The Most Important C++ Non-Book Publications…Ever, he shares his picks for the five most important non-book publications in the history of C++, and, again, along with why he chose them.
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.
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.
These are mostly related to systems’ programming:
- Professional System Library – a free, open-source COM library that offers a simple, generic and logical API for accessing most commonly used information about the system and the environment in which the client application is running, e.g. security, privileges, processes, threads, drivers, services, network, memory, etc. There is also Professional System Library: Introduction article at CodeProject giving brief introduction to the library.
- Authors of 32 OpenMP traps for C++ developers article did really good job. I have not use OpenMP (multi-platform shared-memory parallel programming API for C/C++ and Fortran) myself yet, but can easily imagine that this article can save many hours of painful digging into the non-working code.
- A Fiber Class (and Friends) (C++) is introducing fibers and illustrates the implementation of round-robin scheduler for fibers.
- Telling The Difference Between CD and DVD Drives (C++) – might save some time if needed eventually
- Using Raw Input from C# to handle multiple keyboards – despite the article is in C#, it is 1:1 translating to C++.
- Tracing Events Raised by Any C# Object presents the simple-but-general event hooking/tracing class.
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.
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.
Toggle hardware data/read/execute breakpoints programmatically and Hardware breakpoints articles show how to use hardware breakpoints. Source code is available from both places.
Freewave is a free and open-source collection of popular image and signal processing routines designed to accelerate application development, debugging, and optimization on x86-class processor platforms. API is compatible with the Intel Integrated Performance Primitives (see SourceForge and AMD pages for more information).
WinUnit: Simplified Unit Testing for Native C++ Applications article at the MSDN Magazine introduces WinUnit. It is possibile to browse or download the code.