This is the mail archive of the gcc@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

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


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]