previous | index | next

Using typedefs

Rather than referring to gameState pointers as type gameState*, we can use the C++ typedef declaration to simplify:

struct gameStateInfo {
  int pile1;
  int pile2;
};

typedef gameStateInfo* gameState;

Here, gameState is defined to be the name for the type gameStateInfo*, where gameStateInfo is the actual struct type.

Now, no mention of asterisks needs to be made in functions.

void clear(gameState g) {
  g->pile1 = 0;
  g->pile2 = 0;
}


previous | index | next