Overview
| Artifact ID: | 2684b91cfc128996809c0ec34c99677aad5aea18928ae424297c30067ed48d5e |
|---|---|
| Ticket: | b5bd08df8d61b4ea9bf0cc885f790b367c430a9f
The "int" type registration should be restored. |
| User & Date: | jan.nijtmans on 2022-11-18 10:36:10 |
Changes
- icomment:
> So extensions have made use Tcl_GetObjType to guess the type and offer a "casting" mechanism that only needs to be used in special cases. This has worked surprisingly well in practice. The 'correct' way to check for a specific type in Tcl is to use functions like Tcl_GetIntFromObj(), Tcl_GetWideIntFromObj(), Tcl_GetBignumFromObj(), and see whether they return TCL_OK or not. Since Tcl uses ducktyping (anything looking like an integer is really an integer), the concept is different from other languages. E.g. in java, '5' is a character, "5" is a string and 5 is an integer. In Tcl, there is no distinction, 5 can be a string, a integer, a wideInteger, a bugnum, even a list (with just a single element). You cannot be sure, until you call a function to check that, it's objType just says something about how it is stored internally at the moment. The extension I have seen, check the objType just as optimization: If an object has some type already, you don't need to call Tcl_GetXXXFromObj() to know the real type. In Tcl 8.6, asking for the type of 5, it might be NULL, or tclListType or tclIntType or tclWideIntType. In Tcl 8.7, it will never return tclIntType (since it uses tclWideIntType internally everywhere). In Tcl 9.0, tclIntType is gone, but tclWideIntType is named "int" for maximum compatibility. Yes, it means that extensions need to be adapted, hopefully they start using Tcl_GetIntFromObj()/Tcl_GetWideIntFromObj()/Tcl_GetBignumFromObj() to check for the realy type in stead of depending on the objType. That's my 2c
- login: "jan.nijtmans"
- mimetype: "text/x-fossil-wiki"