“Professional Assembly Language” by Richard Blum

I’ve been looking for a good x86 assembly language book for some time.  First, I picked up “Assembly Language Step-by-Step” by Jeff Duntemann (ISBN 0471578142) for cheap as a remainder.  I wasn’t too impressed with that book, mostly because it was a little too short on details, the coverage was oriented towards 16-bit instructions and DOS and the writing style was a little too chatty for my tastes.  It seems that because assembly language is riddled with machine details, authors feel the need to be chatty to get the reader past the details.  Speaking for myself, I’d rather they just went into the details and left the chitchat for cocktail parties.

Read the rest of this entry »

Refactoring: Replace Integer With Boolean

You have an integer variable holding one of two values used as a conditional flag.

Replace the integer with a boolean variable.

Motivation

The C language did not provide a true boolean type until C99[1], so integer variables containing 0 or 1 (or any non-zero value) are often used as a substitute. Programmers that have built habits from C compilers often use integer variables as boolean flags. In a language with true boolean types, such as C99, C++, C# and Java, a boolean type should be used along with the constants for true and false to more clearly convey the usage of the variable.

Read the rest of this entry »

Refactoring: Convert C to C++

You have C source code.

Create a C++ source file containing the C source code, modified to adhere to the rules of C++.

Motivation

The C language provides limited scoping and encapsulation of data and functions. It has no objects, but legacy systems often involve a large body of procedural code that could benefit from object-oriented refactorings. In order to apply object-oriented refactorings the code must first be ported to C++. Then the C++ code can be refactored from procedural code and data into objects. The objects can be further refactored with standard object-oriented refactorings.

C++ is syntactically compatible with C, but introduces new reserved keywords that are not present in the C language, such as template, typename, class and so-on. Because these additional keywords are reserved in C++ but not in C, you may need to apply Rename Function, Rename Field or Rename Variable refactorings in order to eliminate errors arising from compiling the source with a C++ compiler instead of a C compiler.

C++ is link compatible with C when external data and functions are declared with “C” linkage via the extern "C" in the C++ code. Data and functions made available to C compilation unit from a C++ compilation unit must also be declared extern "C" in order to be visible to the C code.

Read the rest of this entry »