bug-bash
[Top][All Lists]
Advanced

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

Re: Bash arithmetic doesn't give error message on wrap.


From: Paul Jarc
Subject: Re: Bash arithmetic doesn't give error message on wrap.
Date: Mon, 30 Apr 2007 18:09:11 -0400
User-agent: Gnus/5.110003 (No Gnus v0.3) Emacs/21.4 (gnu/linux)

Andreas Schwab <address@hidden> wrote:
> address@hidden (Paul Jarc) writes:
>> result=a*b;
>> if (result/a!=b) { report overflow; }
>
> That won't work, since (signed integer) overflow is undefined in C.  A
> compiler is allowed to optimize the condition to false.

Right, operations would have to be performed in unsigned arithmetic
and then adjusted for the proper sign, range chaecking, etc., to get
signed results.


paul




reply via email to

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