C macros' argument type checking trick.

The preprocessor in C is a very powerful tool which have at least one flaw: there is no type checking on macro arguments. Consider the following trivial (and completely useless) example:

Compiles silently and bugs silently, not good ! So here is a trick to add type checking on your macros' arguments: use _Generic !

Et voila!

in All, C programming,
Copyright 2021-2024 Baillehache Pascal