ned14 / pcpp

A C99 preprocessor written in pure Python
Other
220 stars 41 forks source link

no additional space after macro #29

Closed OmegaDoom closed 5 years ago

OmegaDoom commented 5 years ago

Hello.

For example we have following:

#define FUNC(rettype) rettype

FUNC(void)foo()
{
}

gcc -E output:

void foo()
{
}

pcpp output:

voidfoo()
{
}
OmegaDoom commented 5 years ago

microsoft preprocessor behaves like pcpp - vs-2017 e-preprocess-to-stdout Unfortunately i need gcc behavior. I preprocess a file where this issue is present and i cannot change the source.

ned14 commented 5 years ago

An interesting corner case. I'll look into it, but it won't be until May.

OmegaDoom commented 5 years ago

Thank you! An interesting article - msvc-preprocessor-progress-towards-conformance

Sei-Lisa commented 5 years ago

Wave also behaves like pcpp. The standard doesn't say anything about this, because according to it, the tokens output by the preprocessor are fed to the compiler with no text conversion in the middle. Standalone preprocessors that generate text output are not contemplated in the standard.

Arguably, however, a standalone preprocessor should ensure that parsing its output using a C compiler's tokenizer produces the same sequence of tokens that the compiler would take if they were integrated, and one obvious method is inserting whitespace between some tokens, as GCC does. IIRC this has ugly implications and corner cases that GCC does not cover.

ned14 commented 5 years ago

Fixed in trunk, though I can see loads more corner cases that might now break in future :)