Why is #define bad and what is the proper substitute?

Define it as a constant variable. It is a good programming practice.

const wchar_t *dItemName = L"CellPhone";

In case you need to know the lenght of your string somewhere later, then define it as an array:

const wchar_t dItemName[] = L"CellPhone";

Also, why #define is bad: It transforms all places where you use word dItemName to L”CellPhone”. Example:

struct {
  int dItemName;
} SomeStruct;

will become invalid:

struct {
  int L"CellPhone";
} SomeStruct;

Leave a Comment