Practical, Pragmatic, C++
RSS icon Email icon Home icon
  • C++ Types 1

    Posted on April 22nd, 2009 wozname No comments

    What is a Type?

    What is a type? It’s a good question, it’s something that programmers take for granted every day. Yet we don’t step back and ponder exactly what a type is. A type is a description of how a physical representation maps to a more abstract concept. Remember that all the computer knows about, are bits, which can either be 0 or 1. Imagine a set of three bits, 010, by themselves they don’t mean anything. The computer certainly doesn’t know their meaning. So we have to give them some meaning. They could mean the number 2, which really is the simplest meaning. Alternatively they could be a set of signals or flags with each bit signalling that something is either on or off. Those are the two simplest interpretations of the bits, as a number or a set of flags.

    There is now a second level of meaning that you could attach to those bits. If they are interpreted as a set of flags, the next question is what do the flags actually represent? There is a big difference between the second bit representing that a disk is present or it signalling that the program should launch all the thermonuclear weapons. This meaning is also it’s type. The bit pattern 010 has a different interpretation depending on whether it’s set to be the DiskDriveFlags type or the WeaponsOfMassDestructionFlags type.

    If the set of bits is a number they could either be signed or unsigned, this is important because the bits 110 would have quite different interpretations if they are signed or unsigned. (Typically they would be either -2 if they are signed or 6 if unsigned.)

    We can take it up to the next level of abstraction again, what does the number actually represent? It could represent a represent a count, a magnitude, a velocity, a time or any other basic measure. Now up to the next level, what does the count represent? The number of nuclear bombs on the base or the amount of coffee remaining in the pantry? There is a big difference between the two and we don’t want to mix them up.

    So as you can see types, are very important for interpreting raw data. Without types we wouldn’t be able to make head or tail of the raw bit patterns. In general more complex types are built up of simpler types and a type can be as (conceptually) as big as you want.

    Happy Programming :)

  • Those damn header files

    Posted on April 21st, 2009 wozname No comments

    Here’s a list of the standard header files

    These are the standard header files used by the various C and C++ standards, I’ve shown how they correspond to some of the standards. I have also shown which ones are present in Visual Studio 2008 Express Edition Service Pack 1 (VS2008 EE SP1) as well as two of the Windows SDKs.

    C++ Header Files

    Header File

    C++03

    TR19768(TR1)

    TR18015

    VS2008 EE SP1

    SDK v6.0

    SDK v6.1

    <algorithm>

    Yes

    Yes

    Yes

    Yes

    <array>

    No

    Yes

    Yes

    No

    No

    <bitset>

    Yes

    Yes

    Yes

    Yes

    <complex>

    Yes

    Yes

    Yes

    Yes

    Yes

    <deque>

    Yes

    Yes

    Yes

    Yes

    <exception>

    Yes

    Yes

    Yes

    Yes

    <fstream>

    Yes

    Yes

    Yes

    Yes

    <functional>

    Yes

    Yes

    Yes

    Yes

    <hardware>

    No

    Yes

    No

    No

    No

    <iomanip>

    Yes

    Yes

    Yes

    Yes

    <ios>

    Yes

    Yes

    Yes

    Yes

    <iosfwd>

    Yes

    Yes

    Yes

    Yes

    <iostream>

    Yes

    Yes

    Yes

    Yes

    <istream>

    Yes

    Yes

    Yes

    Yes

    <iterator>

    Yes

    Yes

    Yes

    Yes

    <limits>

    Yes

    Yes

    Yes

    Yes

    <list>

    Yes

    Yes

    Yes

    Yes

    <locale>

    Yes

    Yes

    Yes

    Yes

    <map>

    Yes

    Yes

    Yes

    Yes

    <memory>

    Yes

    Yes

    Yes

    Yes

    <new>

    Yes

    Yes

    Yes

    Yes

    <numeric>

    Yes

    Yes

    Yes

    Yes

    <ostream>

    Yes

    Yes

    Yes

    Yes

    <queue>

    Yes

    Yes

    Yes

    Yes

    <random>

    No

    Yes

    Yes

    No

    No

    <regex>

    No

    Yes

    Yes

    No

    No

    <set>

    Yes

    Yes

    Yes

    Yes

    <sstream>

    Yes

    Yes

    Yes

    Yes

    <stack>

    Yes

    Yes

    Yes

    Yes

    <stdexcept>

    Yes

    Yes

    Yes

    Yes

    <streambuf>

    Yes

    Yes

    Yes

    Yes

    <string>

    Yes

    Yes

    Yes

    Yes

    <strstream>

    Yes

    Yes

    Yes

    Yes

    <tuple>

    No

    Yes

    Yes

    No

    No

    <type_traits>

    No

    Yes

    Yes

    No

    No

    <typeinfo>

    Yes

    Yes

    Yes

    Yes

    <utility>

    Yes

    Yes

    Yes

    Yes

    <unordered_map>

    No

    Yes

    Yes

    No

    No

    <unordered_set>

    No

    Yes

    Yes

    No

    No

    <valarray>

    Yes

    Yes

    Yes

    Yes

    <vector>

    Yes

    Yes

    Yes

    Yes

    Read the rest of this entry »

  • Ever wondered about Wow64?

    Posted on April 21st, 2009 wozname No comments

    I have, especially about the crazy part where 32 bit dlls go into C:\Windows\SysWow64 and 64 bit dlls go into C:\Windows\System32.

    This guy has a good summary of wow64 on his blog:

    http://blogs.msdn.com/craigmcmurtry/archive/2004/12/14/301155.aspx

    Cheers

    Happy Programming :)

  • C++ Standard Alphabet Soup

    Posted on April 20th, 2009 wozname No comments

    C and C++ are international standards. So if you want, you can visit www.iso.org where they’ll be happy to charge way too much for a copy of the standard. It’s best to let your employer pick up the cost of this.

    There are some alternate places where you can obtain draft copies of the standard, if not the standard itself.

    www.open-std.org hosts a set of organisations working on various programming language standards. The two of interest to us would be ISO/IEC JTC1/SC22 WG14 and ISO/IEC JTC1/SC22 WG21, who produce the standards ISO/IEC 9899:1999 and ISO/IEC 14882:2003 respectively. In laymans terms: the two groups of guys who make the C and C++ standards.

    Read the rest of this entry »

  • Beginning C++ 3, Setting up your Development Tree

    Posted on April 19th, 2009 wozname No comments

    Setting up your Development Tree

    Your development tree is basically the directory structure that holds your source code, it can be as big and as elaborate as you like however it should have only one root.

    Before you rush in and start programming, it’s a good idea to think about where your development tree should be. I believe it is best to put your development tree in a user readable/writable part of your directory hierarchy. The most obvious place to put it, is under the “My Documents” folder for your user. If you put it anywhere else, you need to remember you will need to adjust the permissions of the tree so that all the users who need to use it have access.

    The form your development tree should take is a vast topic, with many variations possible. Here are a few simple guidelines to follow while working on your development tree.

    Read the rest of this entry »

  • Beginning C++ 2, Creating the Build Environment

    Posted on April 18th, 2009 wozname No comments

    Creating the Build Environment

    In this article I’ll describe how to setup the Visual C++ 2008 build environment on the Windows platform.

    Windows Platforms and the SDK
    The simplest Windows build environment consists of just the operating system and the freely downloadable platform SDK. The platform SDK consists of all the header files, library files, debug files (pdbs) that are needed to develop applications on Windows. It also comes with the compilers and linkers needed to compile any of C++ or C# programs you might create. However it lacks a User Interface for development so you would have to do all your development with the command prompt and a text editor.

    An alternative free windows platform is to use Visual Studio C++ Express Edition. This package includes a slightly older version of the platform SDK but it has the excellent Visual Studio Integrated Development Environment (IDE) packaged in with it.

    Read the rest of this entry »

  • Beginning C++ 1, Setting up the Platform

    Posted on April 16th, 2009 wozname No comments

    Setting up the Platform

    In this article I’ll be covering the prerequisites for setting up windows to be developer friendly

    As you probably already know, you can build C++ programs on many, many platforms. The one I’ll be concentrating on here will be the Microsoft Windows platform (Windows XP upwards) using the Visual C++ 2008 compiler and the Boost library build environment

    It’s debatable where the platform ends and the build environment begins. Traditionally the platform is a combination of the operating system and the hardware architecture. The build environment is the combination of the compiler and various libraries. The compiler and the libraries you use can have a significant effect on the nature of the language and your code. I’ll expand more on this in later articles.

    Read the rest of this entry »