Lambosaurus / py-c-preprocessor

Tools for preprocessing C files in python
MIT License
15 stars 3 forks source link

Space padding for varargs is not quite right #16

Open Lambosaurus opened 1 month ago

Lambosaurus commented 1 month ago

When substituting regular arguments, the arguments are stripped of surrounding whitespace.

#define macro(a,b)  (a,b)
macro(1,    2) // 1,2

When substituting varargs, the arguments are given a single leading and trailing whitespace, depending on the input.

#define STR_IMPL(x) #x
#define STR(x) STR_IMPL(x)
#define macro(...)  (__VA__ARGS__)
STR((macro(1,   2 ,3      4))) // "(1, 2 ,3 4)"

To be honest, I don't really have much interest in replicating this behavior exactly - it only seems to cause an actual issue when stringifying the output. Stringifying macros with varargs seems like enough of an edge case for me to not care.

@NotYourFox - you implemented this initially, so really just interested in your opinion.

NotYourFox commented 1 month ago

Well, I guess just replacing multiple whitespaces with a singular would fix the issue. Maybe I will get around to fixing that soon.