8
28
Fork
You've already forked antcc
2

preprocessor issue #2

Closed
opened 2026年02月27日 13:29:49 +01:00 by uj · 2 comments

urs% cat /tmp/tt.c
#include <stdio.h>
#define STRINGIFY(x) #x
#define PARENT(x) STRINGIFY(x)
#define COMMA_ARG(a,b,c) a+b+c
int main(void) {
printf("Comma: %s\n", PARENT(COMMA_ARG(1,2,3)));
return 0;
}

urs% for c in gcc clang tcc nvc icx antcc ; do $c -E -std=c11 tt.c -o xx.i && echo -n $c" "; $c -dumpversion ; grep Comma: xx.i ; done
gcc 15
printf("Comma: %s\n", "1+2+3");
clang 17.0.6
printf("Comma: %s\n", "1+2+3");
tcc 0.9.28rc
printf("Comma: %s\n", "1+2+3");
nvc 26.1
printf("Comma: %s\n", "1+2+3");
icx 21.1.1
printf("Comma: %s\n", "1+2+3");
antcc 0.1.8
printf("Comma: %s\n", "1 + 2 + 3" );

urs% cat /tmp/tt.c #include <stdio.h> #define STRINGIFY(x) #x #define PARENT(x) STRINGIFY(x) #define COMMA_ARG(a,b,c) a+b+c int main(void) { printf("Comma: %s\n", PARENT(COMMA_ARG(1,2,3))); return 0; } urs% for c in gcc clang tcc nvc icx antcc ; do $c -E -std=c11 tt.c -o xx.i && echo -n $c" "; $c -dumpversion ; grep Comma: xx.i ; done gcc 15 printf("Comma: %s\n", "1+2+3"); clang 17.0.6 printf("Comma: %s\n", "1+2+3"); tcc 0.9.28rc printf("Comma: %s\n", "1+2+3"); nvc 26.1 printf("Comma: %s\n", "1+2+3"); icx 21.1.1 printf("Comma: %s\n", "1+2+3"); antcc 0.1.8 printf("Comma: %s\n", "1 + 2 + 3" );
Owner
Copy link

Token spacing is a known issue. I've been putting off fixing it because it seems fairly convoluted when nested macro expansions, token pasting etc are involved and I haven't yet set aside the time to think about the best way to implement it. GCC has a whole page about it

Token spacing is a known issue. I've been putting off fixing it because it seems fairly convoluted when nested macro expansions, token pasting etc are involved and I haven't yet set aside the time to think about the best way to implement it. [GCC has a whole page about it](https://gcc.gnu.org/onlinedocs/cppinternals/Token-Spacing.html)
Owner
Copy link

Should be fixed with 1ebf3669f9. Each raw token keeps track of whether it is preceded by whitespace and that is what is used when emitting preprocessed output/stringifying. Macros and macro argument expansions need special handling for their first token. Also there is a thing GCC calls paste avoidance: given #define PLUS +, stringifying PLUS+ gives "++" (because there is no whitespace in the replacement list), but when emitting the preprocessed output it should have a space, + +, so they aren't treated as a single token. There's edgecases regarding ## token pasting too, can't be 100% sure I'm accounting for every obscure thing. -E output is certainly much nicer to look at now at least.

Should be fixed with 1ebf3669f9. Each raw token keeps track of whether it is preceded by whitespace and that is what is used when emitting preprocessed output/stringifying. Macros and macro argument expansions need special handling for their first token. Also there is a thing GCC calls paste avoidance: given `#define PLUS +`, stringifying `PLUS+` gives `"++"` (because there is no whitespace in the replacement list), but when emitting the preprocessed output it should have a space, `+ +`, so they aren't treated as a single token. There's edgecases regarding ## token pasting too, can't be 100% sure I'm accounting for every obscure thing. `-E` output is certainly much nicer to look at now at least.
lsof referenced this issue from a commit 2026年05月30日 12:16:34 +02:00
Sign in to join this conversation.
No Branch/Tag specified
trunk
v0.3.3
v0.3.2
v0.3.1
v0.3.0
v0.2.9
v0.2.8
v0.2.7
v0.2.6
v0.2.5
v0.2.4
v0.2.3
v0.2.2
v0.2.1
Milestone
Clear milestone
No items
No milestone
Projects
Clear projects
No items
No project
Assignees
Clear assignees
No assignees
2 participants
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
lsof/antcc#2
Reference in a new issue
lsof/antcc
No description provided.
Delete branch "%!s()"

Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?