bug-bash
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Arithmetic expression: evaluation order bug


From: Alain D D Williams
Subject: Re: Arithmetic expression: evaluation order bug
Date: Fri, 30 Dec 2022 07:37:56 +0000
User-agent: Mutt/1.10.1 (2018-07-13)

On Fri, Dec 30, 2022 at 12:15:38AM +0100, Steffen Nurpmeso wrote:
> Ah, wait..
> 
> Alain D D Williams wrote in
>  <20221229215700.GD16276@phcomp.co.uk>:
>  ...
>  |Anyway: back to what the shell should be doing. You cannot put a ';' \
>  |into (( ))
>  |as a sequence point, but the manual does say:
>  |
>  |"Sub-expressions in parentheses are evaluated first and may override the
>  |precedence rules above"
>  |
>  |So use sub-expressions to 'evaluate first' so you should prolly rewrite:
>  |
>  |(( i += j += i += i ))
>  |
>  |as:
>  |
>  |(( i += (j += (i += i)) ))
> 
> I had tried that with clang (and now with gcc -Wall).

My quote from "the manual" is the bash manual (version 5.0.3 on Debian 10
(Buster)) so the 'evaluate first' applies to bash not the C language. Please
understand that different languages might do things differently.

-- 
Alain Williams
Linux/GNU Consultant - Mail systems, Web sites, Networking, Programmer, IT 
Lecturer.
+44 (0) 787 668 0256  https://www.phcomp.co.uk/
Parliament Hill Computers Ltd. Registration Information: 
https://www.phcomp.co.uk/Contact.html
#include <std_disclaimer.h>



reply via email to

[Prev in Thread] Current Thread [Next in Thread]