Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > gnu.bash.bug > #15231

expression evaluation problem

From L A Walsh <bash@tlinx.org>
Newsgroups gnu.bash.bug
Subject expression evaluation problem
Date 2019-07-24 09:39 -0700
Message-ID <mailman.2152.1563986395.2688.bug-bash@gnu.org> (permalink)
References <5D3889D2.3090101@tlinx.org>

Show all headers | View raw


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 gnu.bash.bug | Previous | Next | Find similar | Unroll thread


Thread

expression evaluation problem L A Walsh <bash@tlinx.org> - 2019-07-24 09:39 -0700

csiph-web