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,
91 views
I'm open for work ! Check my profile and email me.
Liked this article ? Please consider supporting me:
Copyright 2021-2023 Baillehache Pascal