Vite Decorum Vite Decorum - 17 days ago 5
C Question

Alternative (args...) token for the CL compiler

What is the alternative token (args...) for the CL compiler?

#define DECLARE_C_ARRAY(__type, __name, __page, __args...) \
enum { __name##_page_size = __page }; \
typedef __type __name##_element_t; \
typedef C_ARRAY_SIZE_TYPE __name##_count_t; \
typedef struct __name##_t {\
volatile __name##_count_t count;\
volatile __name##_count_t size;\
__name##_element_t * e;\
__args ;\
} __name##_t, *__name##_p;


Example for the GCC compiler

Answer

Take a look to Variadic macros

Variadic macros are a new feature in C99. GNU CPP has supported them for a long time, but only with a named variable argument (‘args...’, not ‘...’ and __VA_ARGS__). If you are concerned with portability to previous versions of GCC, you should use only named variable arguments. On the other hand, if you are concerned with portability to other conforming implementations of C99, you should use only __VA_ARGS__.

Change

#define DECLARE_C_ARRAY(__type, __name, __page, __args...) \

to

#define DECLARE_C_ARRAY(__type, __name, __page, ...) \

and

__args ;\

to

__VA_ARGS__;\

Unfortunately, this method does not work, if we exclude the args

In this case, remove the semicolon __VA_ARGS__\ (but pass-it when args is used).

An example: http://rextester.com/GYVS61567