#2408 incr of neumeric values for '08' and '09' fails

obsolete: 8.4.1

Tcl Version: 8.4.1
Os Platform: AIX

Problem Behaviour:

When I set a variable to 08 or 09 and then gives
increment command its fails, giving an ERROR "expected
integer but got "08" (looks like invalid octal number)".

But if i assign value equals to 05 or 06 and then issue an
incr command it gives a proper result.

Please refer the Wish output

% set r 07
% incr r
% set r 08
% incr r
expected integer but got "08" (looks like invalid octal
% info tclversion
% info patchlevel

So, the output must be consistent for all values, like 05
it must give an error while incrementing its value OR
ELSE for 08 and 09, it must not give an ERROR.


  • miguel sofer

    miguel sofer - 2003-07-14

    Logged In: YES

    This is not really a bug ... although it bugs plenty of
    people. See for instance

    Tcl will interpret a string of digits starting with 0 as an
    integer in base 8 (octal). Now 07 is a valid octal number
    (value seven), but 08 is not - the number eight is written
    010 as an octal. Hence the "looks like an invalid octal"
    message. In this sense, an invalid octal is a string of
    digits starting with 0 and containing at least an invalid
    octal digit (8 or 9).

    Workaround: remove a possible leading zero with
    set r [string trimleft $r 0]
    and use [format] at the endofyour calculations if you need
    topad with zeros.

  • miguel sofer

    miguel sofer - 2003-07-14
    • status: open --> closed-invalid
  • Donal K. Fellows

    Logged In: YES

    Using [string trimleft] can be a bad idea if you might have
    to deal with the value 0. A better workaround is to do:
    scan $r %d r
    (Otherwise, I agree 100% with the assessment. There is a
    TIP to alter this behaviour, but it is not accepted yet.)


Get latest updates about Open Source Projects, Conferences and News.

Sign up for the SourceForge newsletter:

JavaScript is required for this form.

No, thanks