Last active
June 27, 2019 10:09
-
-
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.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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