#include <cstdio>
//number of arguments to a function macro
#define $numargs_( $1, $2, $3, N, ... ) N
#define $numargs( ... ) $numargs_( __VA_ARGS__, 3, 2, 1 )
#define $paste_( $0, $1 ) $0 ## $1
#define $paste( $0, $1 ) $paste_( $0, $1 )
//maximum is 3 arguments
//easy to get more
#define $check1( $macro, $1 ) $macro( $1 );
#define $check2( $macro, $1, $2 ) $check1( $macro, $1 ) $check1( $macro, $2 )
#define $check3( $macro, $1, $2, $3 ) $check2( $macro, $1, $2 ) $check1( $macro, $3 )
//using $numargs and $paste to get correct macro name
#define $checkall_( $macro, $check, ... ) $check( $macro, __VA_ARGS__ )
#define $checkall( $macro, ... ) $checkall_( $macro, $paste( $check, $numargs(__VA_ARGS__) ), __VA_ARGS__ )
#define $mymacro( $arg ) printf("arg = %d\n", $arg)
int main() {
$checkall( $mymacro, 1, 2, 3 );
}
I2luY2x1ZGUgPGNzdGRpbz4KCi8vbnVtYmVyIG9mIGFyZ3VtZW50cyB0byBhIGZ1bmN0aW9uIG1hY3JvCiNkZWZpbmUgJG51bWFyZ3NfKCAkMSwgJDIsICQzLCBOLCAuLi4gKSBOCiNkZWZpbmUgJG51bWFyZ3MoIC4uLiApICRudW1hcmdzXyggX19WQV9BUkdTX18sIDMsIDIsIDEgKQoKI2RlZmluZSAkcGFzdGVfKCAkMCwgJDEgKSAkMCAjIyAkMQojZGVmaW5lICRwYXN0ZSggJDAsICQxICkgJHBhc3RlXyggJDAsICQxICkKCi8vbWF4aW11bSBpcyAzIGFyZ3VtZW50cwovL2Vhc3kgdG8gZ2V0IG1vcmUKI2RlZmluZSAkY2hlY2sxKCAkbWFjcm8sICQxICkgJG1hY3JvKCAkMSApOwojZGVmaW5lICRjaGVjazIoICRtYWNybywgJDEsICQyICkgJGNoZWNrMSggJG1hY3JvLCAkMSApICRjaGVjazEoICRtYWNybywgJDIgKQojZGVmaW5lICRjaGVjazMoICRtYWNybywgJDEsICQyLCAkMyApICRjaGVjazIoICRtYWNybywgJDEsICQyICk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