|
|
|
|
|
by jstimpfle
2388 days ago
|
|
The one feature from C99 that I rely on (from the top of my head) is designated initializers which is still not in C++... enum {
FPGAPARAM_FOO,
FPGAPARAM_BAR,
FPGAPARAM_BAZ,
NUM_FPGAPARAM_KINDS
};
struct FpgaparamInfo {
const char *name;
int address;
int args;
};
static struct FpgaparamInfo fpgaParamInfo[NUM_FPGAPARAM_KINDS] = {
[FPGAPARAM_FOO] = { "FOO", 0x1337, -1 },
[FPGAPARAM_BAR] = { "BAR", 0x666, -1 },
[FPGAPARAM_BAZ] = { "BAZ", 0x42, -1 },
};
The FpgaParamInfo is basically a mapping from a FPGAPARAM_??? value to additional information. We can make as many of these mappings as we want, and can define them where we want, which means it's all nicely modular. That's not really possible when modelling in a OOP fashion.I really like this style of programming since it's data first and it minimizes the amount of actual code. Designated initializers are important because the order in which the items in "fpgaParamInfo" are given doesn't matter. Without designated initializers, programming in this style would probably lead to many hard to find bugs when the enum is changed and not all associated data items are updated. |
|