30/06/2020
The C99 <stdint.h> header provides a plethora of type definition for platform-independent safe code: int_fast16_t, for example, provides an integer that plays well with the machine but has at least 16 bits. The int_fastxx_t and int_leastxx_t defines doesn’t guarantee a tight fit, they provide an machine-efficient fit. They find the fastest type of integer for that machine that respects the constraint.

But let’s take the problem the other way around: what about defines that gives you the smallest integer, not for the number of bits (because that’s trivial with intxx_t) but from the maximum value you need to represent?
Read the rest of this entry »
Leave a Comment » |
C-plus-plus, C99, data compression, data structures, hacks | Tagged: Bits, C, C Preprocessor, C99, Log2, Portable software, template |
Permalink
Posted by Steven Pigeon
09/01/2018
Recently on Freenode channel ##cpp, I saw some code using an include-all-you-can header. The idea was to help beginners to the language, help them start programming without having to remember which header was which, and which headers are needed.
Is that really a good idea?
Read the rest of this entry »
Leave a Comment » |
C-plus-plus, hacks, programming | Tagged: C, C Preprocessor, cmath, cpp, cstddef, cstdint, fstream, iomanip, iostream, list, Map, stl, Vector |
Permalink
Posted by Steven Pigeon
02/11/2010
When you develop software, you’re always dealing with dependencies, and, if you’re lucky (or have made a quite enlightened choice of dependencies), you don’t have to worry too much about version numbers. But what if you do?

Read the rest of this entry »
5 Comments |
C, Life in the workplace, programming | Tagged: C Preprocessor, cpp, include guards, version, version number |
Permalink
Posted by Steven Pigeon
29/06/2010
In a previous post I discussed some aspects of the C preprocessor (hereafter the CPP) that are evil. Turns out that this week, I had another problem related to a bad usage of the CPP. It didn’t take long to fix, but I can understand why it could be long to figure out.

And while the bug was caused by a careless use of the CPP, I think there’s a couple of simple things we can do to help avoid these.
Read the rest of this entry »
1 Comment |
Bash (Shell), C, Life in the workplace, Portable Code, programming, rants | Tagged: #define, bug, C Preprocessor, cpp, debug, debugging, evil, macro, meta-programming |
Permalink
Posted by Steven Pigeon
17/11/2009
The C (and C++) preprocessor is a powerful but dangerous tool. For sure, it helps with a number of problems, from conditional code inclusion to explicit code generation, but it has a few problems. In fact, more than a few. It is evil.

The C preprocessor (hereafter CPP) should be used with extreme care. For one thing, the CPP doesn’t know about the language it is applied on, it merely proceeds to the translation of the input using very simple rules, and this can leads to tons of hard to detect—and to fix—problems.
Read the rest of this entry »
9 Comments |
C, C99, hacks, programming | Tagged: #define, #ifdef, #undef, bug, C, C Preprocessor, C99, cpp, eviiiiiiil, eviiiil, evil, macro, operator precedence, sequence point, translation unit |
Permalink
Posted by Steven Pigeon
03/02/2009
Yesterday, at least at the time I am writing this entry, I spoke about the Zune and its time bug that caused so many of the devices to just freeze on boot. It its clear that this bug is the result of poor testing (in addition to a poor implementation of a conversion using loops rather than explicit divisions and moduli) and this week, I’d like to tell you about one of my tricks to debug code.
Read the rest of this entry »
2 Comments |
C, C99, hacks, Life in the workplace, programming | Tagged: #define, C Preprocessor, debug, design by contract, fence, GNU CPP, GNU CPP bug, GNU CPP bug no it's not a bug we won't fix it, macro, Magic Numbers, memory allocation |
Permalink
Posted by Steven Pigeon