Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > gnu.bash.bug > #15231 > unrolled thread
| Started by | L A Walsh <bash@tlinx.org> |
|---|---|
| First post | 2019-07-24 09:39 -0700 |
| Last post | 2019-07-24 09:39 -0700 |
| Articles | 1 — 1 participant |
Back to article view | Back to gnu.bash.bug
This discussion starts older than the indexed window; earlier articles aren't shown. The article labeled Started by
below is the oldest one visible, not the original post.
expression evaluation problem L A Walsh <bash@tlinx.org> - 2019-07-24 09:39 -0700
| From | L A Walsh <bash@tlinx.org> |
|---|---|
| Date | 2019-07-24 09:39 -0700 |
| Subject | expression evaluation problem |
| Message-ID | <mailman.2152.1563986395.2688.bug-bash@gnu.org> |
shopt -o expand_aliases
my=declare int='my -i'
my str='cf80'
int v=960 uxtra=1 c=0
# In evaluating this expression:
((v = v | ( uxtra>=++c ? ((0x${str:2*c:2}) & 63) << (6*(uxtra-c)) : 0 )))
I get 985 and not 960 as expected
Which only happens when 'c' is 0 in the middle 'str' expression,
but the ++c should increment 'c' to '1' before it is tested to be
less than or equal to 'uxtra'(=1). Then it would take the 1st or
2nd sub expression depending on that. But the test has to happen
1st, which would pre-increment 'c' to 1. If 'c' is 1, then it should
return '80' from 'str' combine with 0x to make 0x80 or 128. That,
anded with '63' should be 0, shouldn't it?
So why isn't it evaluating to '0', 'or'ed with 960, and giving 960?
Indeed, if I manually put a '1' in place of that 'c' in the middle
of the expression, I get the expected answer of 960. So it seems
'c' is evaluating as '0', even though the middle sub-expression
can't be taken/evaluated until 'c' has been incremented to 1.
BASH=4.4.12
Thanks
-linda
Back to top | Article view | gnu.bash.bug
csiph-web