Hi Guys,
Do you know how to use # & ## operator in C?
For example, what's meaning for following code?
#define macro(a) #a
# can be used for turning an identifier into a string and ## can be
used to create an identifier from a macro's arguments, although I find
## hurts more than it helps. Once a set of code get's large enough,
## starts to make it harder to understand because the names of the
generated variables and functions can no longer be searched for as
easily. They're hidden behind macros.
#include <stdio.h>
#define PRINT_INT(x) \
do { printf("value of %s: %d\n", #x, x); } while(0)
#define CALL_FUNC(x) do { Func##x(); } while(0)
void FuncRead()
{
printf("Entered FuncRead\n");
}
void FuncWrite()
{
printf("Entered FuncWrite\n");
}
int main()
{
int my_variable = 57;
PRINT_INT(my_variable);
CALL_FUNC(Read);
CALL_FUNC(Write);
return 0;
}