Skip to content

## next to whitespace concatentes with the whitespace. #93

@mrolle45

Description

@mrolle45

pcpp tends to keep whitespace tokens around when they are found in the source file. Normally, this is benign because they wind up getting passed to the output. In fact, sometimes (like whitespace between two identifiers) you want to see some space between them in an output file.
However, when there's a ## operator, it's supposed to ignore any adjacent whitespace and stitch together the next tokens before and after it.
pcpp doesn't do that.
Take the example from C99 6.10.3.3.

#define hash_hash # ## #
#define mkstr(a) # a
#define in_between(a) mkstr(a)
#define join(c, d) in_between(c hash_hash d)
char p[] = join(x, y); // equivalent to
                       // char p[] = "x ## y";

Running pcpp on this example produces

char p[] = "x # # y";

The ## operator produces a single token with a " " value (two space characters).
Incidentally, when this is later stringized by the mkstr() macro, it is replaced with a single space, correctly following C99 6.10.3.2. That is why you see "x # # y" rather than "x # # y".

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions