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


Reply via email to