I thought about an example of this problem that had always stuck in my mind, a computer program I had written long ago. It was a simulation of the card game Spades, and I originally wrote it in the Pascal programming language.

A deck of cards has four suits: spades, hearts, diamonds, and clubs. Within each suit, there are thirteen ranks: 2, 3, 4, 5, 6, 7, 8, 9, 10, J, Q, K, and A. The deck therefore lent itself to being represented by a two-dimensional array, with one dimension being the suits and one dimension being the ranks.

Pascal supports four predefined data types. This includes integer (whole numbers), real (floating point or decimal numbers), boolean (either TRUE or FALSE), and char (a letter or symbol). And there was a fifth data type called an enumeration, where the programmer can specify the possible values. For example, spades, hearts, diamonds, and clubs. An enumeration was the perfect data type to represent the suits.

For the ranks, another enumeration was created to represent 2 through ace. The deck then was a matrix with one dimension going from spades to clubs, and the other dimension going from 2 to ace. This is exactly how a human would naturally think of the deck.

However, I ran into a problem when porting my program to the C language. In Pascal, an array could have any integer range (or an enumerated equivalent) for its indexes. But in C, every array had to be indexed from 0.



Next: Page 77
Current: Page 76
Previous: Page 75
Table of Contents: Mesothelioma Lawyers, New York


Privacy Policy