Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

In C function declaration 'params, …)' equal to 'params…)'?

all
In glusterfs’s functions, there is one as follows
NOTES: the whole define in stack.h

//libglusterfs/src/glusterfs/stack.h

#define STACK_WIND(frame, rfn, obj, fn, params...)                             \
    STACK_WIND_COMMON(frame, rfn, 0, NULL, obj, fn, params)

#define STACK_WIND_COMMON(frame, rfn, has_cookie, cky, obj, fn, params...)     \
    do {                                                                       \
        ...  \
        next_xl_fn(_new, obj, params);                                         \
        THIS = old_THIS;                                                       \
    } while (0)

I did not google search anything about explaining such declaring methods, any idea will be appreciated?

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

params... as part of function-like macro is a GNU extension before C standardized ellipsis as part of arguments of function-like macros.

See https://gcc.gnu.org/onlinedocs/cpp/Variadic-Macros.html#Variadic-Macros

Nowadays, prefer __VA_ARGS__.

In C function declaration ‘params, …)’ equal to ‘params…)’?

No, they are not equal in function-like macros. The first one needs to use __VA_ARGS__ to reference variadic arguments and use __VA_OPT__ or ##__VA_ARGS__ to remove leading comma. In the params... then params is straight up replaced by all the arguments including commas.

Doing just ellipsis , ...) and using __VA_ARGS__ would be equal to , params...) and using `params.

In normal functions params... as part of parameter-list is just invalid.

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading