C language adds macro functions and performs function name adaptation

#define metadata_parser_macro(b) \
static uint32_t metadata_parser_ ## b ## bit( \
        const image_buff a, \
{ \...
}

Define a macro function in this way, the name of the macro function can be compiled and initialized through b

For example, if you want to implement two data types now, you only need to declare it twice, which is similar to the template function, but because it is a C language, you cannot use the C++ template function, so this macro method realizes a similar template. function of function

metadata_parser_macro(8);
metadata_parser_macro(16);

Later, just call the function name corresponding to the macro

uint32_t metadata_parser_8bit(...)
uint32_t metadata_parser_16bit(...)

Then the variables inside can also be written using uint##b##, which can achieve a similar effect to the template function

Guess you like

Origin blog.csdn.net/qq_31638535/article/details/129506589