Skip to content

Instantly share code, notes, and snippets.

@pmttavara
Last active June 27, 2019 10:09
Show Gist options
  • Save pmttavara/b59617aa6b2e27c847dced032f9f79f6 to your computer and use it in GitHub Desktop.
Save pmttavara/b59617aa6b2e27c847dced032f9f79f6 to your computer and use it in GitHub Desktop.
(for Ryan Fleury's stream) Variant of the X macro that doesn't require undefinition or redefinition of macros.
// Whatever, just example instructions.
#define INSTRUCTION_TYPE_LIST(instruction_type) \
instruction_type(push, sizeof(u32)) \
instruction_type(pop, sizeof(u32)) \
instruction_type(move, sizeof(u32 *) + sizeof(u32 *))
// Examples of usage (I didn't quite catch what the real usage was):
#define instruction_enum_name(name, size) Instruction_Type_ ## name,
#define instr_size(name, size) (size_t)size,
enum Instruction_Type {
INSTRUCTION_TYPE_LIST(instruction_enum_name)
Instruction_Type_count,
};
// Don't need to #undef anything.
size_t InstructionSizes[] = {
INSTRUCTION_TYPE_LIST(instr_size)
};
// Don't need to #undef anything!
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment