[prev in list] [next in list] [prev in thread] [next in thread] 

List:       busybox
Subject:    Re: semantics: prefix and postfix, "++" and "--" operators
From:       Cristian Ionescu-Idbohrn <cristian.ionescu-idbohrn () axis ! com>
Date:       2009-04-20 18:06:12
Message-ID: 0904202003320.17933 () somehost
[Download RAW message or body]

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
_______________________________________________
busybox mailing list
busybox@busybox.net
http://lists.busybox.net/mailman/listinfo/busybox
[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic