tinycc-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [Tinycc-devel] gcc/tcc nested macros difference


From: Michael Matz
Subject: Re: [Tinycc-devel] gcc/tcc nested macros difference
Date: Sun, 24 Apr 2016 21:19:20 +0200 (CEST)
User-agent: Alpine 2.20 (LSU 67 2015-01-07)

Hi,

On Sun, 24 Apr 2016, Edmund Grimley Evans wrote:

The C standard has a somewhat unclear description of how the
preprocessor should work, but there is general agreement about what
was intended, and the general agreement leaves no real option for
alternative behaviour. Therefore, if two modern C compilers preprocess
differently, then one of them is buggy... I think it's TCC that is
buggy in this case. Has TCC always had this bug, or was it introduced
recently?

Actually, while the text of the standard is somewhat confusing, I think it requires the behaviour of GCC. 6.10.3.6 (c99) Example 3, lists (somewhat shortened) this example:

#define f(a) f(x * (a))
#define x 2
#define g f
#define t(a) a
t(t(g)(0) + t)(1)

which is required to expand to:
f(2 * (0)) + t(1)

from which we can infer that object-like macros _are_ considered for expansion of function-like invocations ("g(0)" is replaced by "f(2 * (0))", which can only happen if "g" is replaced by "f" first), while function like macros are _not_ considered for non-function-like invocations (that wouldn't make much sense anyway).

TCC get's this example correct as well, but problems appear when there are nested invocations of this rule, as your next example shows:

Simplified test case:

#define Y(x) Z(x)
#define X Y
X(X(foo))

which tcc replaces by "Z(Y(1))" showing an inconsistency in TCC itself. Both X should be replaced in the same way (ultimately to Z).

So, your bug entry seems quite appropriate.


Ciao,
Michael.



reply via email to

[Prev in Thread] Current Thread [Next in Thread]