Skip to content
Tcl Source Code Artifact [b83626df50]
Login

Artifact [b83626df50]

Artifact b83626df505ae3a654557f63f93f307cc0708f18:

Ticket change [b83626df50] - Ticket [699060ffffffffff|699060ffff] <i>format %08x 32/64bit confusion</i> status still Open with 4 other changes by srwarren on 2003-04-19 01:49:18.
D 2003-04-19T01:49:18
J icomment Logged\sIn:\sYES\s\nuser_id=728162\n\nDonal,\n\nSome\smore\sfeedback\son\sthis\sissue\snow\sI've\sinvestigated\nthings\sa\slittle\sfurther.\n\nI\sassume\sthat\syour\smost\srecent\sresponse\sindicates\sthat\nyou've\supdated\sthe\sformat\scommand\sto\suse\s\nGET_WIDE_OR_INT\ninternally\sto\sconvert\sany\sstrings\sto\sintegers,\sso\sthat\nit\suses\sthe\s"appropriate"\sinternal\srepresentation.\nI\ssay\sthis\safter\slooking\sat\show\sTclExecuteByteCode\sdoes\nthe\ssame\sthing\sfor\se.g.\sINST_ADD.\n\nThen,\sthe\sformat\scode\swill\slook\sat\swhat\stype\sthat\smacro\ncreated,\sand\sformat\sbased\son\sthat,\swithout\schanging\sthe\ninternal\srepresentation\sbased\son\sthe\sformat\sspecification?\nIf\sso,\swill\sthe\suseWide\sflag\sbe\sused\sfor\s%d/%x\setc.\sany\nmore?\sI'm\snot\ssure\swhat\sit\swould\sdo\sexcept\schange\sdefault\nprecision,\swhich\swouldn't\smake\ssense,\ssince\sthe\sdefault\nwould\sjust\sbe\sto\sprint\sthe\sentire\snumber?\n\nMore\sgeneral\scomments:\n\nI'm\sassuming\sGET_WIDE_OR_INT\sis\sintended\sto\sbe\sused\nthroughout\sthe\sTcl\scode\swhere\sconversions\sfrom\sstring\sto\ninteger\sare\srequired,\sand\sthat\sthe\sintent\sof\sthat\sfunction\nis\sto\sstore\sthe\sconverted\sresult\sinto\sthe\s"appropriate"\ninternal\srep.\sOn\sarchitectures\swith\sjust\slong,\sit'll\suse\nthat.\sOn\sarchitectures\swhere\slong\sand\swide\sare\sdifferent,\nit'll\suse\sthe\ssmallest\stype\sthat\scan\srepresent\sthe\nconverted\svalue\scorrectly.\n\nI'm\sstill\sunclear\swhy\shaving\sboth\sTclIntType\sand\nTclWideIntType\sis\sa\sgood\sidea.\sYour\sprevious\sresponses\nstate\sthat\supdating\sformat\sto\salways\sconvert\sto\swides\nwould\scause\sproblems.\sCan\syou\sexpand\son\sthis?\sI\swould\nhave\sthought\sthe\sbest\simplementation\swould\shave\sbeen\nsomething\slike:\n\n#if\slong_is_native_64_bit_type\ntypedef\slong\sTclIntType;\n#else\sif\ssomething_else_provides_64_bits\ntypedef\ssomething_else\sTclIntType\n#else\ntypedef\sint\sTclIntType\n#endif\n\nThat\sway,\sthere's\sonly\sever\sone\sinternal\srepresentation\non\sintegers,\sthat\salways\sprovides\sthe\smaximal\s"capacity"\nthat\sthe\sunderlying\sCPU/toolchain/OS\ssupports.\n\nThere\sappears\sto\sbe\sa\sproblem\swith\sthe\scurrent\sdesign\nwhere\smultiple\stypes\sare\sused.\sIf\sI\shave\stwo\svariables\nsetup\sas\sshown\sbelow:\n\nset\sa\s0x7fffffff\nset\sb\s0x80000000\n\nthen\sif\sI\sinterpret\sthese\sas\sintegers\ssomewhere,\sthe\ninternal\srep\sfor\sa\sbecomes\sTclIntType,\swhereas\sthe\ninternal\srep\sfor\sb\sbecomes\sTclWideIntType.\n\nNow,\sthere's\sno\sproblem\swith\sthis\sfrom\sthe\spoint\sof\sview\nof\sa\sTcl\sscript\swriting\sprovided\sthis\sis\scompletely\ntransparent\sto\sthem.\sHowever,\sthere\sare\ssubtle\nside-effects\sthat\sare\svisible\sfrom\sTcl\sscripts.\n\nFor\sexample,\ssee\sthe\sfollowing\sscript:\n\n--------------------\nset\sa\s0x7fffffff\nset\sb\s[expr\s$a\s+\s1]\n\nset\sc\s0x80000000\n\nputs\s"b:\s[format\s%d\s$b]\s[format\s%ld\s$b]\s[format\s%x\s$b]\s\n[format\s0x%lx\s$b]"\nputs\s"c:\s[format\s%d\s$c]\s[format\s%ld\s$c]\s[format\s%x\s$c]\s\n[format\s0x%lx\s$c]"\n--------------------\n\nOn\smy\ssystem\s(same\sas\splatform\sinfo\sin\sa\sprevious\nresponse\sbelow),\sthis\sproduces\sthe\soutput\sbelow\s(using\na\scopy\sof\sTcl\swithout\sthe\shack\sI\smentioned\sin\sa\sprevious\nresponse\sto\sthis\sbug\sreport)\n\n--------------------\nb:\s-2147483648\s-2147483648\s80000000\s0xffffffff80000000\nc:\s-2147483648\s2147483648\s80000000\s0x80000000\n--------------------\n\nGiven\sthat\sI\sdidn't\stell\sTcl\swhich\sstorage\ssize\sto\suse\n(I\sdon't\sthink\sthere's\sany\sway\sto\sdo\sthat\sright?)\sand\ngiven\sI\sknow\sTcl\sis\scapable\sof\sstoring\s64bit\sintegers\non\smy\splatform,\sI\swould\sexpect\sboth\sb\sand\sc\sto\scontain\nthe\sexact\ssame\svalue,\sor\sat\sleast\sappear\sthat\sway\sin\nany\sTcl\soperation,\ssuch\sas\sformatting\sor\sequality\stests.\n\nI\ssee\sthree\spossible\sfixes\sfor\sthis\sinteger\soverflow\nproblem.:\n\na)\sUpdate\sINST_ADD\s(and\smuch\sother\scode)\sto\scover\sall\n\s\s\sthe\scorner\scases\srequiring\spromotion\sof\sthe\sinternal\n\s\s\stype.\sThis\swould\sprobably\sbe\sa\slot\sof\swork\s-\n\s\s\scomplicated\sand\serror-prone.\n\nb)\sUpdate\sall\sTcl\sinternal\smath\sto\suse\swides,\sthen\n\s\s\sback-convert\sto\sint/long\sif\sit'll\sfit\son\sarchitectures\n\s\s\swhere\sthey're\sdifferent.\sI'm\snot\ssure\swhat\sthe\spoint\n\s\s\sof\shaving\stwo\stypes\swould\sbe\sthen.\n\nc)\sGet\srid\sof\sthe\stwo\stypes\sand\sjust\shave\sone.\n\nOn\stop\sof\sthis,\sthe\sTcl\scode\shas\sa\shuge\samount\sof\nconditional\scode\sto\ssupport\sthe\stwo\sdifferent\sinternal\nreps\sof\sinteger\svalues.\sThe\scode\scould\sbe\s*drastically*\nsimpler\swith\sa\ssingle\smaximal-size\srepresentation\s-\nfewer\sbugs\sand\seasier\smaintenance!\n\nFrom\sa\sgeneral\sphilosphical\sperspective\son\show/why\sTcl\ndeals\swith\splatforms\swhere\slong\sisn't\s64bit\sbut\ssomething\nelse\sis,\scan\syou\scomment\son\sall\sthis\sso\sI\sunderstand\swhy\neverything\sis\sthe\sway\sit\sis,\sand\sif\sthere's\sanything\sI\ncan\sdo\sto\swrite\smy\sTcl\scode\sso\sit\sbehaves\smore\slike\sI\nexpect\sit\sto\sin\sthe\scode\ssample\sabove.\n\nHaving\sjust\sfound\sTIP72,\sI\ssee\sthere\sis\ssome\ssupposed\nneed\sfor\sa\s32-bit\stype\sto\sremain\sfor\sbackwards\ncompatibility.\sHowever,\sI\sdon't\sknow\sthat\sanything\sever\nstated\sthat\sTcl\sintegers\swere\scategorically\s32-bit\sbefore\nthis\sTIP\swas\simplemented.\sIndeed,\sthe\scode\slooks\slike\nintegers\swere\s32-bit\sor\s64-bit\sdepending\son\swhat\sthe\nunderlying\sCPU/toolchain/OS\ssupported\sas\s"long".\n\nAs\ssuch,\sI\scontend\sthat\sany\sextensions\setc.\sthat\srely\son\nint\sbeing\s32-bit\sare\sbroken\sand\sI\swould\srather\ssee\s*that*\ncode\sbe\sfixed,\sinstead\sof\smassively\scomplicate\sthe\sTcl\ncode\sto\scontinue\ssupporting\sthis\sincorrect\sextension\ncoding.\n\nI\sdon't\shonestly\ssee\show\sTcl\scan\sbe\seasily\s100%\sfixed\nwith\sthe\scurrent\sdual-type\sstructure\s-\sand\seven\sif\sit\sis\nfixed\snow,\sit's\sjust\stoo\seasy\sto\saccidentally\sintroduce\nmore\sproblems\sof\sthis\sexact\ssame\stype\sin\sthe\sfuture.\n\nThanks\sfor\sany\scomments!\n\n
J login srwarren
J mimetype text/plain
J username srwarren
K 699060ffffffffffffffffffffffffffffffffff
U srwarren
Z 99a7f0027f2060ea902984f020af6a98