function - can someone explain this short segment of C++ code, I can't make heads or tails of it -
#include <opcodes.h> const char *getopcodename( uint8_t op ) { #define opcode(x, y) if((0x##y)==op) return "op_" #x; opcodes #undef opcode return "op_unknown"; } link code here: https://github.com/znort987/blockparser/blob/master/opcodes.cpp
here link included opcodes.h
i understand strangely formatted function, however, wondering * @ beginning of function name means. assume has pointers?
also, how #undef , #define statements valid? there's no semicolon after either one, , 1 of them seems defined one-line function. (0x##y) mean? return "op_" #x mean? haven't ever come across syntax before.
i want c++ more seriously, it's hard when looking @ code tell going on. how can learn syntax , rules effectively?
run code thru c++ preprocessor, e.g. using g++ -wall -c -e opcodes.cpp > opcodes.i inside generated opcodes.i
#define not statement preprocessor directive.
the macro opcodes gets expanded big chunk, notably containing opcode( nop, 61) expanded
if ((0x61)==op) return "op_" "nop"; the 2 string literals concatenated one, "op_nop" here.
gcc has documentation on cpp preprocessor. read stringification (with single # ending #x; of opcode macro) , concatenation (with double ## (0x##y) of opcode macro).
Comments
Post a Comment