Tcl Source Code

View Ticket
Login
Ticket UUID: 419692
Title: c++ & tcl.h inclusion of varargs.h
Type: Bug Version: None
Submitter: nobody Created on: 2001-04-28 03:52:54
Subsystem: 52. Portability Support Assigned To: nobody
Priority: 5 Medium Severity:
Status: Closed Last Modified: 2002-06-22 04:43:52
Resolution: None Closed By: jenglish
    Closed on: 2002-06-21 21:43:52
Description:
Regarding the inclusion of stdarg.h vs varargs.h in
tcl.h.

The ISO C++ standard, Section 16.8, says that whether
__STDC__ is set, and the value it is set to, is
implementation-defined.  I.e., it's useless for C++. 
As a matter of fact, some C++ compilers (e.g. KAI's
KCC) define it or not define it according to the custom 
of the vendor's C++ compiler, since the vendor's
headers expect likewise. 

The proper fix is for the header file to adhere to the
rules in Section 16.8, and use: 

#if defined(__STDC__) || defined(HAS_STDARG) || \  
defined(__cplusplus)
#   include <stdarg.h>

etc.  Alternately define HAS_STDARG if __cplusplus
is defined.
User Comments: jenglish added on 2002-06-22 04:43:52:
Logged In: YES 
user_id=68433

This should be fixed now (generic/tcl.h r1.126).  The new
logic is:

#if !defined(NO_STDARG)
#   include <stdarg.h>
    /* ... */
#else
#  include <varargs.h>
#endif

where NO_STDARG  is undefined by default.   This should
keep  C++ compilers happy as long as they're relatively
recent (post-1990 or so).

dgp added on 2001-05-04 04:17:40:
Logged In: YES 
user_id=80530

Well, the C++ standard has moved on.  The standard
thing to do in C++ is:

#include <cstdarg>

but that's not C-compatible, so we won't be doing that.

The problem with relying on configure to sort things out
is that the header file tcl.h is included in the compiling
of other C/C++ programs that link the Tcl library.  These
other programs may or may not be using autoconf to manage
their Makefiles, etc.

In that case, though, it seems the advice to pass back
to the submitter is that he/she should add -DHAS_STDARG
in the approprate place(s) in his/her build system.

hobbs added on 2001-05-04 03:45:16:
Logged In: YES 
user_id=72656

The submitter doesn't make an argument as to why C++ should 
always include stdarg.h and not varargs.h.  Is that also in 
the C++ standard now?  If so, then apply the patch, 
otherwise it seems like HAS_STDARG should somehow get 
defined at the appropriate step (perhaps in configure).

dgp added on 2001-04-28 12:31:19:

File Added - 5805: stdarg.patch

Logged In: YES 
user_id=80530

This report accurately describes standard C++.  In fact,
in our own C++ code that embeds the Tcl library, we
always include tcl.h like so:

#ifdef __cplusplus
extern "C" {
#  ifndef HAS_STDARG
#    define HAS_STDARG
#  endif
#endif

#include <tcl.h>

#ifdef __cplusplus
}// end of extern "C"
#endif

However, Tcl has a history of supporting lots of
nonstandard compilers.  Lines 206-208 of tcl.h
indicate that at least at one time it was useful
to support a compiler that defined __cplusplus,
but preferred <varargs.h> to <stdarg.h>.

Unfortunately those lines date back to the pre-CVS
days of Tcl, so I can't retrieve any CVS history that
explains their purpose.

I have no objection to the request, but I would like
to understand the purpose of lines 206-208 before we
(effectively) yank them out.

In case we decide to go ahead with this, I attach the
patch.

Attachments: