semantics: prefix and postfix, "++" and "--" operators
Cristian Ionescu-Idbohrn
cristian.ionescu-idbohrn at axis.com
Mon Apr 20 18:06:12 UTC 2009
On Mon, 20 Apr 2009, Denys Vlasenko wrote:
> 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
But of course you're right. Sorry about that. My tests were wrong.
Cheers,
--
Cristian
More information about the busybox
mailing list