Skip to content
Tcl Source Code Ticket Change Details
Login

Ticket Change Details

Overview

Artifact ID: bf7395f332ccc80924ee4c61c364ead7b29b177c
Ticket: 1cc44617e2b4ed0a29f75762d45fe46388260f74
Mechanism with 64 bit support in tcl.h does not work outside of core
User & Date: anonymous on 2017-03-23 19:04:49
Changes

  1. assignee changed to: "nobody"
  2. closer changed to: "nobody"
  3. cmimetype changed to: "text/html"
  4. comment changed to:
    For 64 bit support in tcl.h the following constants will be used: TCL_WIDE_INT_TYPE (on 32 bit arch) or TCL_WIDE_INT_IS_LONG (on 64 bit arch).
    
    <p>
    With Mac the following (stripped) code seems to work:
    
    <verbatim>
    #ifdef __APPLE__
    #   ifdef __LP64__
    #       undef TCL_WIDE_INT_TYPE
    #	define TCL_WIDE_INT_IS_LONG 1
    #    else /* !__LP64__ */
    #       define TCL_WIDE_INT_TYPE long long
    #       undef TCL_WIDE_INT_IS_LONG
    #    endif /* __LP64__ */
    #endif /* __APPLE__ */
    </verbatim>
    
    For Windows/Linux/UNIX it cannot work properly, see this annotated code snippet:
    
    <verbatim>
    #if !defined(TCL_WIDE_INT_TYPE)&&!defined(TCL_WIDE_INT_IS_LONG)*
    /*****************************************************************
     This is the case when compiling outside of Tcl core, because none
     of these constants is pre-defined. Mac is excluded here, because
     handled above.
    *******************************************************************/
    #   if defined(_WIN32)
    /******************************************************************
     This branch will be reached when compiling under Windows, even
     when compiling with any other compiler than MSVC.
     Now TCL_WIDE_INT_TYPE will be defined even on 64 bit architectures,
     but due to documentation on 64 bit architectures the constant
     TCL_WIDE_INT_IS_LONG should be defined instead.
     Note that on 64 bit machines the constant _WIN32 is also
     pre-defined.
     Also note that the definition of TCL_WIDE_INT_TYPE is probably
     incorrect when compiling with an other compiler than MSVC.
    *******************************************************************/
    #      define TCL_WIDE_INT_TYPE __int64
    #      ifdef __BORLANDC__
    #         define TCL_LL_MODIFIER  "L"
    #      else /* __BORLANDC__ */
    #         define TCL_LL_MODIFIER  "I64"
    #      endif /* __BORLANDC__ */
    #   elif defined(__GNUC__)
    /******************************************************************
     This is the case when compiling with gcc under Linux/UNIX.
     Now TCL_WIDE_INT_TYPE will be defined, whether 32 bit or 64 bit
     architecture, but due to documentation on 64 bit architectures
     the constant TCL_WIDE_INT_IS_LONG should be defined instead.
     And the definition of TCL_LL_MODIFIER is incorrect on 64 bit
     architectures, should be "l" instead.
    *******************************************************************/
    #      define TCL_WIDE_INT_TYPE long long
    #      define TCL_LL_MODIFIER "ll"
    #   else /* ! _WIN32 && ! __GNUC__ */
    #      ...
    #   endif /* _WIN32 */
    #endif /* !TCL_WIDE_INT_TYPE & !TCL_WIDE_INT_IS_LONG */
    </verbatim>
    
    A technical note: for me it seems to be more logical to change the order for __GCC__ and _WIN32, because the __GCC__ branch works in any case, whether Windows or not:
    
    <verbatim>
    #if defined(__GCC__)
    #   ...
    #elif defined(_WIN32)
    #   ...
    #endif
    </verbatim>
    
    At this place I suggest to use the opportunity for modernizing the definitions of 64 bit support based on C99, see this example:
    
    <verbatim>
    #if HAVE_STDINT_H
    #   include <stdint.h>
    #elif defined(_MSC_VER) && _MSC_VER < 1600
    /* work around for the support of ancient compilers */
    #   include "tkWinStdInt.h"
    #else
    /* this is not expected with compilers from this century, except MSVC (handled above) */
    #   error "C99 support is required - can't include stdint.h"
    #endif
    
    typedef int64_t  Tcl_WideInt;
    typedef uint64_t Tcl_WideUInt;
    
    #if HAVE_STDINT_H
    #   if (UINTPTR_MAX == 0xffffffffu)
    #	define TCL_IS_32_BIT_ARCH
    #   elif (UINTPTR_MAX >= 0xffffffffffffffffu)
            /* We handle >64 bit also as 64 bit architectures. */
    #	define TCL_IS_64_BIT_ARCH
    #   else
    #	error "unsupported architecture" /* can never happen */
    #   endif
    #elif defined(_WIN64) /* ancient compiler support */
    #   define TCL_IS_64_BIT_ARCH
    #elif defined(_WIN32) /* ancient compiler support */
    #   define TCL_IS_32_BIT_ARCH
    #else
    #   error "cannot detect architecture" /* can never happen */
    #endif /* HAVE_STDINT_H */
    
    #if TCL_IS_64_BIT_ARCH
    #   define Tcl_WideAsLong(val)    ((long)(val))
        ...
    #else  /* if TCL_IS_32_BIT_ARCH */
    #   define Tcl_WideAsLong(val)    ((long)((Tcl_WideInt)(val)))
        ...
    #endif /* TCL_IS_64_BIT_ARCH */
    
    #if defined(_MSC_VER) /* only MSVC (Windows) */
    #   define TCL_LL_MODIFIER    "I64"
    #elif defined(TCL_IS_64_BIT_ARCH)
    #   define TCL_LL_MODIFIER    "l"
    #else /* if TCL_IS_32_BIT_ARCH */
    #   define TCL_LL_MODIFIER    "ll"
    #endif /* _WIN32 */
    
    ...
    </verbatim>
    
    <p>
    For file tkWinStdInt.h see repository of Tk project <a href="http://core.tcl.tk/tk/timeline?r=revised_text&nd&c=2017-03-23+10%3A03%3A05&n=200">revised_text</a>. Note that every compiler of these days is supplying the header files <stdint.h> and <inttypes.h> (belongs to C99). The ancient compiler support (old MSVC versions) is only for ActiveState (they don't have enough money for a newer compiler?).
    
    <p>
    Please ote that the Tk developers would benefit with the modern definitions, because in this project <stdint.h> will be used, and also the differentiation between 32 and 64 bit architectures is important for Tk.
    
  5. foundin changed to: "8.6/8.7"
  6. is_private changed to: "0"
  7. login: "anonymous"
  8. priority changed to: "5 Medium"
  9. private_contact changed to: "9b7155594aadef44d10a978838b8fe108cdafdd1"
  10. resolution changed to: "None"
  11. severity changed to: "Important"
  12. status changed to: "Open"
  13. submitter changed to: "anonymous"
  14. subsystem changed to: "69. Other"
  15. title changed to:
    Mechanism with 64 bit support in tcl.h does not work outside of core
    
  16. type changed to: "Bug"