Skip to content
Tcl Source Code View Ticket
Login

View Ticket

[scan _ %d] 64-bit issue

Closed / Invalid0842331eba4e78318b795abcfddf84ad878311f1Created 5 years agoUpdated 3 years ago
Descriptionplain2022-03-14 07:49:32
I'm seeing a platform dependency in the Tcl "scan" command when it comes to conversion of  oversized positive decimal numbers. According to the docs, "scan ... %d" is supposed to return the greatest integer value that makes sense - according to the given size modifiers. Without any size modifier (just %d) I'd expect to get a large positive number. But instead, I get this on a LP64 machine (x64 GNU/Linux):

% info patchlevel
8.6.4
% set tcl_platform(wordSize)
8
% scan 11111111111111111111 %d
-7335632962598440505

...whereas on a ILP32 machine (x86 GNU/Linux) I get this:
% info patchlevel
8.6.4
% set tcl_platform(wordSize)
4
% scan 11111111111111111111 %d
2147483647

I've found old bug #1011860 [https://core.tcl-lang.org/tcl/tktview/1011860fffffffffffff], which seems to be related to this.

What's going on here?
chrstphrchvzwiki2022-04-07 17:53:52

Without any size modifier (just %d) I'd expect to get a large positive number.

The documented behavior of not specifying a size modifier is the same as using the h size modifier, which restricts the range to that of expr int(…) which is determined by $tcl_platform(wordSize). The scan range is unlimited only when the ll size modifier is used.

oehharwiki2022-04-07 19:27:20

Christopher, I enjoy to clicking "approve" for every valuable ticket you provide, it is a honor to do this small service ;-). But maybe, someone gives your user name "chrstphrchvz" at least comment rights, so the moderator approval is not necessary any more... Maybe, this might be ok for you ?

Take care, Harald

fvogelplain2022-04-07 22:00:46
@oehhar: done.
chrstphrchvz Closed ticket [0842331eba]. [History diff]2023-10-09 20:30:42
Log in (anonymous is fine) to add a comment.