Skip to content

Commit

Permalink
Draft a page about counting arguments
Browse files Browse the repository at this point in the history
  • Loading branch information
agagniere committed Aug 27, 2024
1 parent 7e498f9 commit fadcae4
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 0 deletions.
16 changes: 16 additions & 0 deletions book/pages/05_argcount.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
# Counting arguments

:::{admonition} Work In Progress
:class: warning
This page is a draft
:::

If you've made it this far, congratulations !
You've completed the introduction.

We will now start abusing macros and delve into black magic.

The pivotal trick is going to be able to count the number of arguments given to a variadic macro.

:::{preprocessed} 05_first
:::
1 change: 1 addition & 0 deletions book/pages/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,5 @@ Black Magic
02_use
03_log
04_default
05_argcount
quotes
11 changes: 11 additions & 0 deletions book/samples/05_first.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
#include <stdio.h>

#define ARG_COUNT_1(A, B, C, D, E, F, G, H, I, J, ...) J
#define ARG_COUNT_2(...) ARG_COUNT_1(__VA_ARGS__ __VA_OPT__(,) 9, 8, 7, 6, 5, 4, 3, 2, 1, 0)

int main()
{
printf("0: %i\n", ARG_COUNT_2());
printf("1: %i\n", ARG_COUNT_2(1));
printf("2: %i\n", ARG_COUNT_2(1, 2));
}

0 comments on commit fadcae4

Please sign in to comment.