Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
mrolle45 opened this issue Jan 18, 2024 · 1 comment
Open

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

mrolle45 opened this issue Jan 18, 2024 · 1 comment
Labels

Comments

@mrolle45
Copy link

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".

@ned14 ned14 added the bug label Jan 18, 2024
@ned14
Copy link
Owner

ned14 commented Jan 18, 2024

Thanks for the BR

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants