Mon 19 Jan 2004 05:50:53 AM UTC, comment #1:
Your evaluation is not quite correct. Comments ARE ignored. However, in the example above the warning function is evaluated before the comment comes into effect.
Values inside a define/endef do not undergo treatment to remove comments: the lines inside that block are assigned verbatim to the variable.
Next, the call function is invoked on variable "foo", with an argument of "baz". That is completely expanded and the results of that expansion are passed to the eval function to be evaluated.
When the call function evaluates the foo variable as a function, it is not examined for comment characters first, because normally these are stripped off when the value is read in. Because of that, the warning function is evaluated at that time, and the warning is printed. The $(eval ...) reference here is a red herring: you would get the same output if you'd invoked just $(call ...) by itself. By the time the eval function gets the value the warning has been printed and replaced with an empty string, so eval just sees the string "#", which it properly ignores as a comment.
I don't see any way to change this behavior; if call were changed to check for comments then first, that would not be a backward-compatible change, and second we'd have to change all the other functions in that way as well, to be consistent. I'm not even sure it's really incorrect behavior, per se, although I grant you it's surprising at first. But, when using call and eval it's critically important to be very familiar with evaluation of variables, where it happens, and how it works.
|