[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Tinycc-devel] Hmmm...
From: |
Rob Landley |
Subject: |
[Tinycc-devel] Hmmm... |
Date: |
Sat, 8 Sep 2007 05:09:21 -0500 |
User-agent: |
KMail/1.9.6 |
So, if the very first line of a file is an #include it apparently doesn't get
processed. This means that the #include <stdio.h> in hello.c never gets
parsed unless you stick a blank line in front of it. You can see this if you
run "tcc -E hello.c". (Why did nobody notice this before? Doesn't it break
stuff?)
This is due to this chunk of next_nomacro1():
> case '#':
> /* XXX: simplify */
> PEEKC(c, p);
> if ((next_tok_flags & TOK_FLAG_BOL) &&
> (parse_flags & PARSE_FLAG_PREPROCESS)) {
> file->buf_ptr = p;
> preprocess(next_tok_flags & TOK_FLAG_BOF);
> p = file->buf_ptr;
> goto redo_no_start;
> } else {
> if (c == '#') {
> p++;
> tok = TOK_TWOSHARPS;
> } else {
> if (parse_flags & PARSE_FLAG_ASM_COMMENTS) {
> p = parse_line_comment(p - 1);
> goto redo_no_start;
> } else {
> tok = '#';
> }
> }
> }
Every file starts out with next_tok_flags set to 0, so preprocess() never gets
called on it. This is set at the end of next_nomacro1() which gets called
while processing the predefined #defines.
The fix is to initialize next_tok_flags in the file handling loop in main().
I checked to make sure that #!/usr/bin/tcc -run as the first line still gets
ignored properly (it does).
Rob
--
"One of my most productive days was throwing away 1000 lines of code."
- Ken Thompson.
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [Tinycc-devel] Hmmm...,
Rob Landley <=