如何引用m4宏中给定参数列表中的最后一个参数?我需要拉出最后一个参数,并在此基础上生成宏扩展。
发布于 2013-06-07 06:05:34
这并不是特别优雅,但它是有效的:
define(`last',`ifelse(`$#',`0',`',`$#',`1',`$1',`last(shift($@))')')dnl
last(foo,bar,baz)发布于 2016-05-09 04:29:08
# more elegant solution:
changequote([,])
define([LEN], [$#])
define([LAST], [pushdef([$0], $LEN($@))$0($@)[]popdef([$0])])
define([LAST_BUT_ONE], [pushdef([$0], $decr(LEN($@)))$0($@)[]popdef([$0])])
LAST(foo, bar, baz)
LAST_BUT_ONE(foo, bar, baz)https://stackoverflow.com/questions/16961540
复制相似问题