why execute the same script in Solaris and AIX is different?
Closed / Invalid1600214fffffffffffffffffffffffffffffffffCreated 20 years agoUpdated 20 years ago
Descriptionplain2006-11-21 07:46:38
Below is the sample tcl script that I tested.
set TclVar1 0x80000001;
set TclVar2 -2147483647;
set TclFlag 1;
if [ $TclVar1 == $TclVar2 ] {
set TclFlag 1;
} else {
set TclFlag 0;
}
The problem is:
If I use Tcl8.3.2 and run in Solaris8 and AIX4.3,
it will return TclFlag with value 1 which means that variable TclVar1 is equal to TclVar2.
But
If I use Tcl8.4.12 and run in the same Solaris8 and AIX4.3, it will return different results, that is variable TclVar1's value is 1 in AIX, but TclVar2's value is 0 in Solaris.
Why? Is it a bug in updating from Tcl8.3.2 to Tcl8.4.12 or anyone can explain this? Thanks!
dkf Ticket [1600214fff]: 2 changes
[History diff]2006-11-21 16:44:55
dgpplain2006-11-22 00:07:44
Logged In: YES
user_id=80530
Originator: NO
Tcl 8.4.0 added "wide" integers back in 2002,
and when they came in, some of the
rules for interpreting the value
of literals changed to support them.
In this case, the literal "0x80000001"
now means "2147483649" and not "-2147483647".
See TIP 72 for details.
This is entirely a Tcl 8.3 -> 8.4
change. Platform switch has nothing
to do with it in this case. See
these interactive sessions on
one system:
% info patch
8.3.5
% set x 0x80000001
0x80000001
% set y -2147483647
-2147483647
% expr {$x==$y}
1
% info patch
8.4.15
% set x 0x80000001
0x80000001
% set y -2147483647
-2147483647
% expr {$x==$y}
0
Please note that your code
has never been portable to
a 64-bit system:
% info patch
8.3.5
% set x 0x80000001
0x80000001
% set y -2147483647
-2147483647
% expr {$x==$y}
0
The only portable way to limit
integer values exactly to a
32-bit range in [expr] is with masking:
% expr {($x&0xFFFFFFFF)==($y&0xFFFFFFFF)}
1
Alternatively, you might want to
[binary format] your values and compare
the resulting byte sequences, if that's
the comparison you're really trying
to accomplish.
% set bx [binary format i $x]
% set by [binary format i $y]
% expr {$bx eq $by}
1
nobodyplain2006-11-30 08:53:18
Logged In: NO Thanks Don Porter, I got it!
Log in (anonymous is fine) to add a comment.