Coding category archives

Visual C++ exception handling

This article describes a problem with the default handling of exceptions in Microsoft’s Visual C++ compilers. The problem is caused by the compiler’s extension to the C++ exception handling mechanism. I then give a technique that properly exploits this extension, bringing it into line with normal C++ exception handling. This allows programs to deal with [...]

Prefer prefix operators over postfix

Whenever you have a choice, you should use the C++ prefix increment and decrement operators (e.g. ++i) instead of the postfix versions (e.g. i++). This will make your code more efficient, clear and consistent. This advice applies (more or less) to most languages that have both prefix and postfix operators.
1. Efficiency
Code like this is quite [...]

Clarifying C++ negation

The C++ negation operator (!) can be hard to see in code listings, and this leads to bugs. Here are a few solutions to this perennial coding problem.

Disappearing C++ functions

C++ specifies how compilers should deal with programs that misbehave. This article describes one of the effects of these rules: compilers may generate no code for the body of a misbehaved function, whether or not the function is ever called.
Consider this function

void furphy()
{
std:::cerr << “furphy”;
int* p = [...]

Close
E-mail It