Andreas
Andreas

Reputation: 5301

Limit of preprocessor __VA_ARGS__ length?

I'm using a preprocessor macro va_args hack for SQL code to allow pasting directly in sqlite3.exe for that quick no-build debugging:

#define QUOTE(...) #__VA_ARGS__
char const example[] = QUOTE(
  INSERT INTO Some_Table(p, q) VALUES(?, ?);
); 

https://stackoverflow.com/a/17996915/1848654

However this is hardly how __VA_ARGS__ is supposed to be used. In particular my SQL code consists of hundreds of tokens.

What is the limit of __VA_ARGS__ length (if any)?

Upvotes: 1

Views: 476

Answers (1)

melpomene
melpomene

Reputation: 85877

The only thing I can find is this bit in C99 (C11 still contains the same text):

5.2.4.1 Translation limits

  1. The implementation shall be able to translate and execute at least one program that contains at least one instance of every one of the following limits:13)

    • [...]
    • 127 arguments in one macro invocation
    • [...]
    • 4095 characters in a character string literal or wide string literal (after concatenation)
    • [...]

[...]

13) Implementations should avoid imposing fixed translation limits whenever possible.

So according to the standard there is no fixed limit. You will have to check whether your compiler documents any limits or just tries to support whatever you throw at it (until it runs out of RAM or something).

Upvotes: 2

Related Questions