Sunday, November 16, 2008

C++: Anonymous namespaces

The C++ standard now says that the use of the static keyword to declare a file-scope varible as non-externally linkable is deprecated in favour of declaring it inside an anonymous namespace, that is, a namespace with no name. Such variables are guaranteed to be local to that file and can be named concisely without fear of clashes or polluting the global namespace.

That is until you want to start doing unity builds. Unity building is the pre-build process of taking all the .cpp files in a C++ project and #includeing them into a single .cpp file, and then only compiling that single file. Apparently (and surprisingly) this compiles many, many times faster than using seperate files (perhaps because of reduced disc accesses?) at least it does within Visual Studio 2005.

The main point is that you should always to endeavour to make all your variable names unique as you never know when that scope could change.

Reclaimed

I've just reclaimed this blog. It's been ages since I've posted and so much has happened. It is, this very day, my thirty-second birthday, which means I'm only twenty in hexadecimal.