A major drawback of Macro in C/C++ is that the arguments are strongly typed checked i.e. a macro can operate on different types of variables(like char, int ,double,..) without type checking.
Therefore we avoid to use Macro. But after the implementation of C11 standard in C programming, we can use Macro with the help of a new keyword i.e. “_Generic”. We can define MACRO for the different types of data types. For example, the following macro INC(x) translates to INCl(x), INC(x) or INCf(x) depending on the type of x:
#define INC(x) _Generic((x), long double: INCl, \ default: INC, \ float: INCf)(x)
Note: If you are running C11 compiler then the below mentioned output will be come.
3 0 3
This article is contributed by Bishal Kumar Dubey. If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to email@example.com. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please write comments if you find anything incorrect, or you want to share more information about the topic discussed above.
- tmpnam() function in C
- Why variable name does not start with numbers in C ?
- exit() vs _Exit() in C and C++
- Octal numbers in c
- How a Preprocessor works in C?
- C Library math.h functions
- typedef versus #define in C
- exec family of functions in C
- Interesting Facts in C Programming
- Diffference between #define and const in C?
- Interesting Facts about Macros and Preprocessors in C
- Structure Member Alignment, Padding and Data Packing
- Do not use sizeof for array parameters
- gets() is risky to use!
- Why C treats array parameters as pointers?