Short solutions of 2012

Back to Blog

In this section I will collect short things that have taken me some time to figure out. The intent is that I would be able to avoid wasting time in the future after I have forgotten about them.

Visual Studio 2012


Things you want to do:


with `REG_DWORD` value 1. This gets rid of all-uppercase menus.

Disabling iterator checking in Visual Studio 2010


In Visual Studio 2010, the preferred way to disable iterator checking is to define _ITERATOR_DEBUG_LEVEL = 0. The _ITERATOR_DEBUG_LEVEL replaces the different combinations of _SECURE_SCL and _HAS_ITERATOR_DEBUGGING. See here for more information.

Property sheets in Visual Studio 2010


Property sheets are a nice way to set up properties to projects. Each property sheet is a collection of properties for a project. One can attach arbitrarily many property sheets to each project, and the property sheets can be shared between projects. The latter feature is the essential one.

In my solutions at least, the projects share very similar properties. Now I can create just one property sheet for the whole solution and apply that to each project. If I want to change the properties, I will do so in the property sheet.

What’s more, multiple property sheets can be layered so that the union of their properties applies. The sheets are given an order. If two sheets define the same property, then the later one takes priority.

The strategy is to give each solution a property sheet in which to configure output directories, disable warnings, and disable secure-stl etc. You will then make this property sheet part of your solution, in the sense of carrying it around in the version control.

There are also special global property sheets called Microsoft.Cpp.Win32.user and Microsoft.Cpp.Win64.user which are automatically added to each configuration of each project. These will apply properties globally on your computer. If you change to another computer, these settings are lost. These property sheets are ideal for specifying include and library directories for external libraries (which are of course computer-specific). While the former works on 32-bit builds, the latter works on 64-bit builds. Of course, you will want to choose different directories for them.

A bit odd feature of the property sheets is that they won’t get save automatically when you change a property. You must either Save All, or right click on the property sheet and save it. This is unintuitive and causes unnecessary confusion from time to time.

It is useful to notice that a property sheet can be added to all projects and configuration at the same time. Simply select the desired projects or configurations and right click to add an existing property sheet. Unfortunately, it seems a given property sheet can not be removed from all projects at once.

If you need to set project-specific properties, do note that you must explicitly bring in the inherited properties. For example, in the Preprocessor definitions property, this is done by %(PreprocessorDefinitions).

There is a trap in the command-line settings. If you specify Additional Options in a project, then those will not be unioned with the additional options in the property sheets. Unless I am mistaken, it is missing a way to bring in the inherited options. Therefore, you should use the other options explicitly instead. For example, if you need a preprocessor definition, do it in the Preprocessor definitions property instead of as a /D switch in Additional Options.

Bison and flex


In Gnu Flex, we would like the scanner not to include the unistd.h file because it is not a standard file and does not exist on Windows. Later versions of Flex have the %option nounistd. Unfortunately the latest Flex version that can be found for Windows is 2.5.4 and it does not have this option. It is sufficient to create an empty unistd.h file. However, creating the file in the current directory will not do, because it is included as <unistd.h>, that is, the current directory will not be searched. It has to be placed somewhere on the include search path of the compiler.

The lexer can be generated by:

flex -olex_console_scanner.cpp console_scanner.l

In Visual Studio, you can make this automatic as a custom build step. Right click on console_scanner.l, click on Properties, and give the above as a custom build command. Interestingly, the above does not work if the -o option is on the right side. Also note that it is essential to change the name of the output file to .cpp. Otherwise flex will output a .c file, which will be compiled as C code by Visual Studio. This will give errors since the code is actually C++.

Mercurial SSL-certificate


While pushing changes in TortoiseHG, it said that SSL: Server certificate verify failed. The problem is that the certificate in the server is self-signed. Two ways to fix this:

  1. Add to mercurial.ini (Global Settings –> Edit file)
  1. or, in the Synchronization window of TortoiseHg, push the lock-icon to get to the security options, and then select No host validation.

Property sheets for 64-bit platform


After adding the x64 platform to the project in Visual Studio 2010 SP1, the property sheet Microsoft.cpp.x64.user was not created for the projects. This was resolved by restarting the Visual Studio.