Subject: Re: unnecessary .undef after .for loops
To: Roland Illig <>
From: Todd Vierling <>
List: tech-pkg
Date: 05/25/2005 11:05:00
On Mon, 16 May 2005, Roland Illig wrote:

> I have seen many code snippets that use the following pattern:
> .for i in foo bar baz
> # ...
> .endfor
> .undef i
> I have tried the following snippet with bmake (pkgsrc), /usr/bin/make (NetBSD
> 1.6.2) and /usr/bin/make (NetBSD 2.99.15). All three automatically undefine i
> after the loop.

I'm guilty of this too, and having traversed the code of NetBSD's make
".for" implementation, I should know better.  :)

In ".for" loops, the variable name supplied is a special temporary variable
that has some restrictions on how it can be used (particularly in
bootstrap-bmake/NetBSD<=1.6.x).  For the most part it functions as a normal
variable, but the variable data allocated to it is completely destroyed when
the loop exits.

It does, however, also destroy any previous variable with that name set
before the .for begins.

Yes, I believe the .undefs can be removed.  They may be good visual sugar,
but they really do nothing useful.

-- Todd Vierling <> <> <>