semantics: prefix and postfix, "++" and "--" operators
Denys Vlasenko
vda.linux at googlemail.com
Mon Apr 20 00:52:50 UTC 2009
On Sunday 19 April 2009 22:54, Cristian Ionescu-Idbohrn wrote:
> Walter Harms pointed it out, initially. Consider this:
>
> m=999
> echo initial m=$m
> echo "m++" m=$((m++))
> echo "++m" m=$((++m))
> echo "m--" m=$((m--))
> echo "--m" m=$((--m))
>
> math.c defines this:
>
> /* longest must be first */
> static const char op_tokens[] ALIGN1 = {
> ...
> '-','-', 0, TOK_POST_DEC,
> ...
> '+','+', 0, TOK_POST_INC,
>
> Is it TOK_POST_... or TOK_PRE_...?
>
> This works:
>
> echo "++m" m=$((++m))
> echo "--m" m=$((--m))
>
> but not this:
>
> echo "m++" m=$((m++))
> echo "m--" m=$((m--))
It does:
# ./busybox hush -c 'm=1; echo "m++" m=$((m++)); echo m=$m'
m++ m=1
m=2
# ash -c 'm=1; echo "m++" m=$((m++)); echo m=$m'
m++ m=1
m=2
# bash -c 'm=1; echo "m++" m=$((m++)); echo m=$m'
m++ m=1
m=2
--
vda
More information about the busybox
mailing list