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,
136 views
A comment, question, correction ? A project we could work together on ? Email me!
Learn more about me in my profile.

Copyright 2021-2025 Baillehache Pascal