bugTiny C Compiler - Bugs: bug #38557, tcc preprocessor has trouble...


bug #38557: tcc preprocessor has trouble expanding hex numbers

Submitter:  Austin English <austin987>
Submitted:  Wed 20 Mar 2013 08:00:10 PM UTC
Category:  None Severity:  3 - Normal
Item Group:  None Status:  None
Privacy:  Public Assigned to:  None
Open/Closed:  Open
* Mandatory Fields

Add a New Comment Rich Markup

Mon 02 May 2016 12:32:26 PM UTC, comment #4: 

fixed on the [mob]

Sergey Korshunoff <seyko>
Thu 04 Apr 2013 11:07:23 AM UTC, comment #3: 

OK, I was not aware of this thread: http://lists.nongnu.org/archive/html/tinycc-devel/2013-03/msg00018.html

So, we have this:
 #define FOO 0xfe
 char bar[FOO+1];

TCC compiles this code sucessfully in one pass but not when you preprocess it separately with tcc -E because the tcc preprocessor generates:
 char bar[0xfe+1];
and 0xfe+1 is considered as one token instead of three at the second pass.

If you try with gcc -E you can see that a white space is added right after the macro expansion to avoid this problem.

Christophe Staïesse <chastai>
Wed 03 Apr 2013 11:34:49 PM UTC, comment #2: 


The patch to wine was rejected:
"This has nothing to do with the preprocessor. It's a compiler bug."

Austin English <austin987>
Sun 24 Mar 2013 12:45:57 PM UTC, comment #1: 


I use the latest release (0.9.26) and the error occurs in both cases.

In fact, after some investigation, I found out that it's the correct behavior as '0xfe+1' is considered as a number token by the preprocessor. I've learned something today :)

From the C89 standard:
" 3.1.8 Preprocessing numbers:
A preprocessing number begins with a digit optionally preceded by a period (.) and may be followed by letters, underscores, digits, periods, and e+, e-, E+, or E- character sequences."

There is a similar rule in C99 (see 6.4.8).

The solution is to put a space before the sign.

Christophe Staïesse <chastai>
Wed 20 Mar 2013 08:00:10 PM UTC, original submission:  

austin@debian-home:~$ tcc -E foo.c
# 2 "foo.c"

typedef struct _FOO
        unsigned char bar[0xfe+1];
} FOO;

int main(void)
    return 0;
austin@debian-home:~$ tcc -E foo.c -o foo-i.c
austin@debian-home:~$ tcc -c foo-i.c
foo-i.c:5: error: invalid number

if compiling directly, the problem does not appear, only when compiling preprocessed source:
austin@debian-home:~$ tcc -c foo.c
austin@debian-home:~$ ./a.out
austin@debian-home:~$ echo $?

Austin English <austin987>


(Note: upload size limit is set to 16384 kB, after insertion of the required escape characters.)

Attach Files:

No files currently attached


Depends on the following items: None found

Items that depend on this one: None found


Carbon-Copy List
  • -email is unavailable- added by seyko (Posted a comment)
  • -email is unavailable- added by chastai (Posted a comment)
  • -email is unavailable- added by austin987 (Submitted the item)

    There are 0 votes so far. Votes easily highlight which items people would like to see resolved in priority, independently of the priority of the item set by tracker managers.

    Only logged-in users can vote.


    No changes have been made to this item

    Back to the top

    Powered by Savane 3.13-4448.
    Corresponding source code