All pastes #39033 Raw Edit

MrJim

public text v1 · immutable
#39033 ·published 2006-01-29 17:10 UTC
rendered paste body
Q6.
Here are several different ways to declare constants.  What are the pros and cons of each?

A.
#define INDEX_1       0
#define INDEX_2       1
#define INDEX_3       2
#define MAX_INDEX     3



B.
enum
{
    INDEX_1 = 0,
    INDEX_2,
    INDEX_3,
    MAX_INDEX
};


C.
typedef enum 
{
    INDEX_1 = 0,
    INDEX_2,
    INDEX_3,
    MAX_INDEX
} INDEX_TYPE;


D.
static const int
INDEX_1   = 0,
INDEX_2   = 1,
INDEX_3   = 2,
MAX_INDEX = 3;


E.
int
INDEX_1   = 0,
INDEX_2   = 1,
INDEX_3   = 2,
MAX_INDEX = 3;