* bug: cpp(1) token pasting failure
@ 2018-09-16 20:54 Nick Owens
2018-09-17 10:17 ` [9front] " Ethan Gardener
0 siblings, 1 reply; 3+ messages in thread
From: Nick Owens @ 2018-09-16 20:54 UTC (permalink / raw)
To: 9front
[-- Attachment #1: Type: text/plain, Size: 1100 bytes --]
the attached C program will fail to be preprocessed by cpp(1) with the
following output. for comparison, the gcc -E test.c output follows as
well. this specific example was extracted from tinycc.
9front cpp(1):
term% cpp concat.c
cpp: concat.c:8 Bad token jo) produced by ##
cpp: concat.c:8 No newline at end of file
cpp: concat.c:8 EOF in macro arglist
cpp: concat.c:8 Disagreement in number of macro arguments
#line 1 "/usr/glenda/code/c/trash/concat.c"
#line 4 "/usr/glenda/code/c/trash/concat.c"
enum token {
TOK_NULL
DEF_ASM(jo #undef DEF};static const char keywords[] = #define DEF(id,
str) str "\0" DEF_ASMTEST(j,)#undef DEF;int main(int argc, char
*argv[]){ return -1;}#line 23
"/usr/glenda/code/c/trash/concat.c"
gcc -E:
mischief@omicron:/tmp $ gcc -E concat.c
# 1 "concat.c"
# 1 "<built-in>"
# 1 "<command-line>"
# 31 "<command-line>"
# 1 "/usr/include/stdc-predef.h" 1 3 4
# 32 "<command-line>" 2
# 1 "concat.c"
enum token {
TOK_NULL
,TOK_ASM_jo
};
static const char keywords[] =
"jo" "\0"
;
int
main(int argc, char *argv[])
{
return 0;
}
[-- Attachment #2: concat.c --]
[-- Type: text/x-csrc, Size: 356 bytes --]
#define DEF_ASM(x) DEF(TOK_ASM_ ## x, #x)
#define DEF_ASMTEST(x,suffix) \
DEF_ASM(x ## o ## suffix)
enum token {
TOK_NULL
#define DEF(id, str) ,id
DEF_ASMTEST(j,)
#undef DEF
};
static const char keywords[] =
#define DEF(id, str) str "\0"
DEF_ASMTEST(j,)
#undef DEF
;
#define DEF(id, str)
int
main(int argc, char *argv[])
{
return 0;
}
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [9front] bug: cpp(1) token pasting failure
2018-09-16 20:54 bug: cpp(1) token pasting failure Nick Owens
@ 2018-09-17 10:17 ` Ethan Gardener
2018-09-17 11:53 ` Nick Owens
0 siblings, 1 reply; 3+ messages in thread
From: Ethan Gardener @ 2018-09-17 10:17 UTC (permalink / raw)
To: 9front
On Sun, Sep 16, 2018, at 9:54 PM, Nick Owens wrote:
> DEF_ASM(jo #undef DEF};static const char keywords[] = #define DEF(id,
> str) str "\0" DEF_ASMTEST(j,)#undef DEF;int main(int argc, char
> *argv[]){ return -1;}#line 23
i thought you could only use preprocessor directives at the start of a line. i'm pretty sure i learned that particular point, but it was probably in the 90s.
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [9front] bug: cpp(1) token pasting failure
2018-09-17 10:17 ` [9front] " Ethan Gardener
@ 2018-09-17 11:53 ` Nick Owens
0 siblings, 0 replies; 3+ messages in thread
From: Nick Owens @ 2018-09-17 11:53 UTC (permalink / raw)
To: 9front
i believe macros can appear anywhere, but that particular output is
the result of cpp(1)'s token pasting failure - it is not the correct
output.
On Mon, Sep 17, 2018 at 3:17 AM Ethan Gardener <eekee57@fastmail.fm> wrote:
>
> On Sun, Sep 16, 2018, at 9:54 PM, Nick Owens wrote:
> > DEF_ASM(jo #undef DEF};static const char keywords[] = #define DEF(id,
> > str) str "\0" DEF_ASMTEST(j,)#undef DEF;int main(int argc, char
> > *argv[]){ return -1;}#line 23
>
> i thought you could only use preprocessor directives at the start of a line. i'm pretty sure i learned that particular point, but it was probably in the 90s.
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2018-09-17 11:53 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2018-09-16 20:54 bug: cpp(1) token pasting failure Nick Owens
2018-09-17 10:17 ` [9front] " Ethan Gardener
2018-09-17 11:53 ` Nick Owens
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).