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 firstname.lastname@example.org. 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.
- Understanding "extern" keyword in C
- Understanding "register" keyword in C
- Use of explicit keyword in C++
- Function overloading and const keyword
- C++ mutable keyword
- Generic Linked List in C
- C++ | Static Keyword | Question 1
- C++ | Static Keyword | Question 2
- C++ | Static Keyword | Question 3
- C++ | friend keyword | Question 1
- C++ | friend keyword | Question 2
- C++ | Static Keyword | Question 4
- C++ | const keyword | Question 1
- C++ | const keyword | Question 2
- C++ | const keyword | Question 3
Improved By : AJ04