Disadvantages of _Generic

The major disadvantages of _Generic are as follows:

  • The major disadvantage of _Generic is its usage in macros as they are vulnerable to errors.
  • It is difficult to understand and debug in case of error due to complex syntax and limited view of expanded code.


_Generics Keyword in C

The _Generic keyword in C is used to implement a generic code that can execute statements based on the type of arguments provided. It can be implemented with C macros to imitate function overloading. The _Generic keyword was first introduced in C11 Standard.

Similar Reads

Syntax of _Generic in C

_Generic( (expression), type_1: statements, type_2: statements, . . default: statements )...

How to use _Generic in C?

We can use the _Generic keyword anywhere in our code where we need some generic code. The below example demonstrates how to use _Generic keyword:...

_Generic in Macros

...

Advantages of _Generic

A major drawback of Macro in C is that the arguments lack type checking, i.e. a macro can operate on different types of variables(like char, int, double,..) without type checking. We can use _Generic to include the statements for different argument types in such macros....

Disadvantages of _Generic

...