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 »

  • 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 »

  • First Post

    Posted on March 17th, 2009 wozname No comments

    This is the first post!

    I have a filing cabinet full of goodness that I can’t wait to share with you.

    More to come…