Skip to content

Instantly share code, notes, and snippets.

View joaovictorvns's full-sized avatar
💻

João Victor Santos joaovictorvns

💻
  • Sergipe, Brasil
View GitHub Profile
@aprell
aprell / va_nargs.c
Last active September 22, 2025 22:26
Counting arguments in variadic macros
// RUN: cc -Wall -Wextra %s && ./a.out
#include <assert.h>
#if defined(__GNUC__) || defined(__clang__)
// Supports 0-10 arguments
#define VA_NARGS_IMPL(_0, _1, _2, _3, _4, _5, _6, _7, _8, _9, _10, N, ...) N
// ## deletes preceding comma if _VA_ARGS__ is empty (GCC, Clang)
#define VA_NARGS(...) VA_NARGS_IMPL(_, ## __VA_ARGS__, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1, 0)
#else