Skip to content
Tcl Source Code Ticket Change Details
Login

Ticket Change Details

Overview

Artifact ID: b2d471c299cc01182d9e50fb2624a89e61e3aa40
Ticket: 565088ffffffffffffffffffffffffffffffffff
Bring tcl.h into the 1990s
User & Date: jenglish on 2002-06-05 23:33:17
Changes

  1. assignee changed to: "jenglish"
  2. cmimetype changed to: "text/plain"
  3. comment changed to:
    Brief summary: <tcl.h> contains several preprocessor
    macros intended to aid source-level compatibility
    between ANSI C and K&R C compilers.  However, the
    #ifdef logic tends to assume K&R C by default and
    enables modern features based on the presence of
    __STDC__ and/or other special cases.
    
    Since pre-ANSI compilers are a rarity nowadays (2002),
    and many compilers do not define __STDC__ in the
    default (non-strict-ansi) mode even though they do in
    fact support all the relevant features, it would make
    more sense to assume modern C by default and only
    enable the backwards-compatibility macros on a
    special-case basis.
    
    I'll put together a patch in the next couple of days.
    
    Detailed analysis (from a post to comp.lang.tcl):
    
    From: [email protected] (Joe English)
    Newsgroups: comp.lang.tcl
    Subject: Re: Build problem using aCC on HP-UX
    Date: 5 Jun 2002 15:32:02 GMT
    Message-ID: <[email protected]>
    
    [...]
    The Tcl core was C89-compatible until the recent
    (8.4a2? 3?)
    addition of "long long", which is a C99 feature. 
    (Actually,
    I'm not sure under which conditions 'long long' is
    actually
    used -- it's tough to decipher what's going on in the
    #ifdef
    chain in tcl.h).
    
    However, the core also includes backwards-compatibility
    #defines for several features which were not present in
    K&R C (VOID, CONST, USE_PROTOTYPE, USE_STDARG, etc.).
    The choice of whether to use C89 or K&R features is
    determined by whether or not __STDC__ is #define'd,
    or, in many cases, with an additional list of special
    cases, e.g.
    
        #   if defined(__STDC__) || defined(__cplusplus) ||
    defined(__BORLANDC__)
    
    Most compilers nowadays (in my experience) are C89, but
    do not yet fully support C99.  Many of these support
    C9X features like "long long", but only when invoked in
    "extensions-enabled" mode.
    
    Here's where the problem comes up: "long long" is
    standard C99,
    but it's an extension to C89; thus 20th century
    compilers don't
    enable it in "strict ANSI" mode and Tcl 8.4 can't be
    compiled
    in that mode.  Most compilers -- GCC being a notable
    exception --
    don't define __STDC__ when extensions are enabled, so
    all of
    the backwards-compatibility cruft in tcl.h gets
    activated
    (except on platforms which have been accounted for by a
    special-case preprocessor test as above).
    
    The correct way to proceed is IMO to bring tcl.h into
    the 1990s:
    it should assume C89 features are present by default
    (void, const,
    stdarg.h, etc.), and only enable the
    backwards-compatibility
    cruft on a special-case basis, instead of the other way
    around.
    For example, instead of:
    
        #if ((defined(__STDC__) || defined(SABER)) &&
    !defined(NO_PROTOTYPE)) \
            || defined(__cplusplus) ||
    defined(USE_PROTOTYPE)
        #   define _USING_PROTOTYPES_ 1
        #   define _ANSI_ARGS_(x)   x
        #   define CONST const
        #else
        #   define _ANSI_ARGS_(x)   ()
        #   define CONST
        #endif
    
    use something like:
    
            #if defined(ANCIENT_COMPILER)
            #       define CONST
            #       define _ANSI_ARGS_(x)
            #else
            #       define _ANSI_ARGS_(x) x
            #       define CONST const
            #endif
    
    where ANCIENT_COMPILER is undefined by default.
    
    
  4. foundin changed to: "None"
  5. priority changed to: "3 Low"
  6. resolution changed to: "None"
  7. status changed to: "Open"
  8. submitter changed to: "jenglish"
  9. subsystem changed to: "52. Portability Support"
  10. title changed to: "Bring tcl.h into the 1990s"
  11. type changed to: "RFE"