help-make
[Top][All Lists]
Advanced

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

Missing arguments to macros


From: Robert Mecklenburg
Subject: Missing arguments to macros
Date: Fri, 15 Nov 2002 09:25:02 -0700

The details of macro argument processing aren't clear to me, so I'm
asking.  It appears that all macro arguments are optional, for
instance,

define g
  $1 $2
endef

The macro g can be called with any number of arguments, e.g.,
"$(call g,a)" or "$(call g,a,b,c)".  Extra arguments are never
expanded/substituted and missing arguments have an empty value.  Is
this correct?

If the above is correct, then I experience an issue when macros call
other macros.  For instance, here "f" takes two arguments, but
passes only one of them to "g" omitting the second argument.

define f
  # Use $1 somehow...
  echo $(call g,$2)
endef

Here lies the issue.  Even though "g" receives only one argument,
"$2" still has the value from "f".  I expect this makefile to print
simply "b", but it prints "b b".  Is this correct?

If I add a comma like this "$(call g,$2,)" (providing an empty
second argument) the code works as expected.


all: ; @$(call f,a,b)

define g
  $1 $2
endef

define f
  # Use $1 somehow...
  echo $(call g,$2)
endef

-- 
Robert





reply via email to

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