[Top][All Lists]

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

Re: iterating over arguments

From: Eric Blake
Subject: Re: iterating over arguments
Date: Mon, 14 Sep 2009 21:17:37 +0000 (UTC)
User-agent: Loom/3.14 (

Sam Steingold <sds <at>> writes:

> >> (drop m4_popdef, replace m4_pushdef with m4_define)
> > 
> > m4_pushdef/m4_popdef is nicer than m4_define, in that your use of the macro 
> > name becomes a local variable (you aren't corrupting state if anything else 
> > the happened to use the same name for an unrelated macro).  
> > m4_define works all right if you have no reason to suspect that the macro 
> > will ever collide.
> interesting.
> I thought that I was modifying a local variable.

In the case of m4_foreach_w([cl_feat]), yes, you happen to be modifying a local 
variable after all, since m4_foreach_w is doing a m4_pushdef/m4_popdef of 
cl_feat under the hood.  But it's nicer to get into good habits, rather than 
relying on internal implementations.

> m4_foreach_w([cl_feat], [$1],
> [ m4_define([cl_feat], ...) ])
> leaks cl_feat outside of m4_foreach_w?

If we ever change how m4_foreach_w is implemented, such that cl_feat is no 
longer managed by an invisible m4_pushdef/m4_popdef, then yes, your raw 
definition of cl_feat would leak.  On the other hand, by doing the m4_toupper 
up front, then you aren't changing how cl_feat is modified under the hood, and 
can guarantee no leak even if we change our implementation.

> > m4_foreach_w([cl_feat], m4_toupper([$1]),
> > [AC_CACHE_CHECK([for cl_feat in CLISP], ....
> even better! will use this!

Glad you agree.

Eric Blake

reply via email to

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