Macro to count number of arguments

后端 未结 4 1685
甜味超标
甜味超标 2020-11-30 06:16

I have a variadic function from a third-party C library:

int func(int argc, ...);

argc indicates the number of passed optional

4条回答
  •  小蘑菇
    小蘑菇 (楼主)
    2020-11-30 06:54

    The full example on Mehrwolf's answer unfortunately doesn't compile on VS2010 nor it does on VS2015 (i tried it also on this online VS compiler). A different approach on this problem that allows to produce cross-platform code that compiles on a wide range of compilers is using non-standard extensions that are also available in MS compilers as in my answer to a similar question. Also, differently form the cited answer, the result of PP_NARG((a, b, c)) using the extensions (in both MS and gcc/clang compilers) is 1 and not 0.

提交回复
热议问题