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!

2021-10-13
in All, C programming,
98 views
Copyright 2021-2024 Baillehache Pascal