Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

C++ preprocessor removes whitespace in calls to variadic macros (Solaris Studio 12.3)

The C++ preprocessor of Oracle Solaris Studio 12.3 removes whitespace completely when expanding __VA_ARGS__.

Can anybody confirm this behaviour on their system? Is it a known compiler bug? Are there any workarounds for this problem?

To illustrate, here is a simple test program, vaargs.c:

#include <stdio.h>

#define PRINT(...) printf("%s\n", #__VA_ARGS__)

int main()
{
    PRINT(hello world);

    return 0;
}

The C preprocessor works as expected:

$ cc vaargs.c -o vaargs && ./vaargs
hello world

$ cc -V
cc: Sun C 5.12 SunOS_i386 2011/11/16

But the C++ preprocessor removes the space between "hello" and "world":

$ CC vaargs.c -o vaargs && ./vaargs
helloworld

$ CC -V
CC: Sun C++ 5.12 SunOS_i386 2011/11/16
like image 428
Claudio Avatar asked Oct 06 '14 15:10

Claudio


1 Answers

This is a compiler bug, as per N3337 16.3.2 (cpp.stringize) p2 (the rest of the quote is snipped):

A character string literal is a string-literal with no prefix. If, in the replacement list, a parameter is immediately preceded by a # preprocessing token, both are replaced by a single character string literal preprocessing token that contains the spelling of the preprocessing token sequence for the corresponding argument. Each occurrence of white space between the argument’s preprocessing tokens becomes a single space character in the character string literal.

like image 164
LThode Avatar answered Sep 24 '22 23:09

LThode