Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

expr with leading zero

10 views
Skip to first unread message

Joachim Winkler

unread,
Sep 5, 1996, 3:00:00 AM9/5/96
to

Hi folks !

Yesterday I got a little problem with the expr function. If I use
operands with leading zero, the interpreter (tcl7.4) returns a syntax
error or the return value is indefinite. This happens only with some
special operands.

Example:

% expr 06 + 3
9

% expr 09 + 5
syntax error in expression "09 + 5"

% expr 012 * 3
30


Why does this happen ??

thnx,
Joachim

--
*********************************************************************
* Joachim Winkler < win...@gkn.de> priv.: 74080 Heilbronn *
* GKN, Abt. LRP I, 74382 Neckarwestheim *
*********************************************************************

JeroenHoppenbrouwers

unread,
Sep 5, 1996, 3:00:00 AM9/5/96
to

Joachim Winkler (win...@gkn.de) wrote:
> % expr 09 + 5
> syntax error in expression "09 + 5"

> Why does this happen ??

According to the Tcl documentation, numbers starting with a zero are
assumed to be OCTAL. '9' is no allowed octal character.

Numbers starting with '0x' are considered hexadecimal.

--
Jeroen Hoppenbrouwers, Senior Researcher at | Stop connecting computers;
Infolab, Tilburg University, The Netherlands | start connecting people!
http://infolabwww.kub.nl:2080/infolab/people/hoppie

Peter Booth

unread,
Sep 10, 1996, 3:00:00 AM9/10/96
to

Joachim Winkler <win...@gkn.de> writes

> Hi folks !
>
> Yesterday I got a little problem with the expr function. If I use
> operands with leading zero, the interpreter (tcl7.4) returns a syntax
> error or the return value is indefinite. This happens only with some
> special operands.
>
> Example:
>
> % expr 06 + 3
> 9
>
> % expr 09 + 5
> syntax error in expression "09 + 5"

The leading zero is used to indicate octal encoding. You get an error for
09 because 9 is not a valid octal digit

Peter Booth


0 new messages