Category Archives: Programming

Pointers and the const keyword

One thing I remember from my early days as a C-programmer as all too easy to mess up is the usage of the const keyword in the context of pointers.

Given the following lines of code, which pointer is a pointer to a constant value, and which is a constant pointer to a value?


int v1, v2;
const int * p1 = &v1;
int * const p2 = &v2;

The simple rule of thumb to decipher this type of declaration, I soon learned, was to read the declaration from the very end.

So, p1 is a pointer to an int that is constant, and p2 is a constant pointer to an int.

Thus, neither of the two expressions would be allowed:


*p1 = 2;
p2 = &v1;

But both these would:


p1 = &v2;
*p2 = 1;

The ‘new’ auto keyword in C++11

Reading up on some of the new C++11-features, and stumbled upon the redefinition of the ‘auto’ keyword.

Though I don’t particularly like the choice to redefine the meaning of an already existing keyword, I do however see some good uses of this new keyword, especially when working with lots of externally produced and poorly documented libraries – something I’m all too familiar with.

Long live the ‘new’ auto keyword!

A simple CRC implementation

Every now and then I find myself worrying about data transmitted over a media now showing up correctly on the other side. The best way to make sure this is the case is to add a CRC calculation to the data being transmitted.

While the web is swamped with implementations of CRC calculations, I still find it useful to have one reliable piece of software doing this type of calculation conveniently at hand, enter this zip archive.

The linked to CRC code was provided by Michael Barr at http://www.barrgroup.com/.