Subject: Re: [ast-developers] ksh -n warning for (( $var )) instead of the  
correct (( var ))?
--------


> Can we get a ksh -n warning if a script uses (( $var )) in arithmetic
> expressions instead of (( var )), e.h. (( var=$var+1 )) instead of the
> correct (( var=var+1 )) ?
> I loathe this a lot and I have to mark this manually currently in all
> code reviews.
> 
> Olga
> 

I agree that ((var=var+1)) is more efficient than (( var=$var+1 ))
since the shell doesn't have to first convert var to a string when
var is an arithmetic type. ((++var)) or ((var+=1)) is even slightly
more efficient. 

However, if someone is writing a strictly conforming shell script
they are forced to use $(($var)) instead of $((var)) since the standard
only requires constant expressions.

Perhaps when invoked as ksh (rather than sh), the warning messages
could check for this.

I will consider this for the next revision.

David Korn
[email protected]
_______________________________________________
ast-developers mailing list
[email protected]
https://mailman.research.att.com/mailman/listinfo/ast-developers

Reply via email to