This is the mail archive of the
gcc@gcc.gnu.org
mailing list for the GCC project.
Strange Scope effects
- From: Thomas Schoebel-Theuer <schoebel at informatik dot uni-stuttgart dot de>
- To: gcc at gcc dot gnu dot org
- Cc: schoebel at eiche dot informatik dot uni-stuttgart dot de (Thomas Schoebel-Theuer)
- Date: Tue, 3 Aug 2004 18:23:09 +0200 (CEST)
- Subject: Strange Scope effects
Hi all,
I am writing a macro preprocessor as a frontend for C, and stumbled
around the following problem:
// macro definition:
f(int x) { some code; }
// outer scope
static int x = ...;
// macro call
f(x)
Generated code looks like this:
({ // inner scope begins
int x = x; // parameter assignment, try to evaluate _once_
some code;
})
AFAIK, in Ada the scope rules are will allow that. The x after the
Ada := will refer to outer x, even while a new x is being defined at the
inner scope.
In Gnu C, I get a stupid assignment of the _uninitialized_ inner
x to itself.
I don't have access to the C99 standard. What is the required semantics?
Is there any chance to fix this?
Well, I already have a workaround by automatically renaming the inner x,
but it would be nice to get the same semantics (and scope rules) as with
ordinary parameter calls. I don't want to use inline functions, because
other parameters may be typeless, and they will be treated as in
ordinary macro processors.
Thomas