Macros with Variable Number of Arguments

Macros with Variable Number of Arguments

Question:
Is there anyway to have a variable number of arguments passed to a macro? Yes, I know it can be done with inline, but this is for debugging purposes.

Answer:
Yes and no. Standard C and C++ don’t support variable number of arguments in a function-like macro. However, the newly approved C99 standard of the C programming language does support function-like macros with a variable number of arguments using the ellipsis (…) notation. The variable arguments (including the separating commas) are “collapsed” into a single extra argument that can be referenced as __VA_ARGS__ within the macro’s replacement list.

If you’re using a C99 compliant C compiler, you can use this feature. In C++, though, you should use superior techniques such as default parameters, templates, and function objects instead of macros.

Share the Post:
data observability

Data Observability Explained

Data is the lifeblood of any successful business, as it is the driving force behind critical decision-making, insight generation, and strategic development. However, due to its intricate nature, ensuring the

Heading photo, Metadata.

What is Metadata?

What is metadata? Well, It’s an odd concept to wrap your head around. Metadata is essentially the secondary layer of data that tracks details about the “regular” data. The regular