TIP 557: C++ support for Tcl

Login
Author:         Jan Nijtmans <[email protected]>
State:          Final
Type:           Project
Vote:           Done
Created:        13-Dec-2019
Post-History:
Keywords:       Tcl
Tcl-Version:    8.7
Tcl-Branch:     cplusplus
Vote-Summary:	Accepted 2/0/3
Votes-For:	JN, KW
Votes-Against:	none
Votes-Present:	DGP, FV, SL

Abstract

Every once in a while there is a request to be able to compile Tcl with a C++ compiler. This would - in theory - allow C++ exceptions thrown by extensions to be handled by Tcl. This TIP is NOT about adding any code to Tcl doing that. But - as a first step - at least, Tcl needs to compile well with a C++ compiler even though we don't use any C++ features.

This TIP proposes making Tcl compilable with a C++ compiler, without actually using any C++ features.

Implementation

The Tcl source-code has been strictified in the following ways:

Nothing is done yet in the Tcl code to handle C++ exception, neither is any of the API now available as C++ classes.

Tk has a cplusplus branch as well, doing the same. This work is complete for UNIX, but not yet for Windows and MacOS.

Caveats

C++ is more strict in using enum's than C is. Enums cannot be stored in ints (and reverse) without type casts in C++. Tcl doesn't use enums, but there was one external API function (in ttk) which actually used enum but its argument in the public API was int: Ttk_GetOrientFromObj. This TIP deprecates Ttk_GetOrientFromObj, and adds a new internal function TtkGetOrientFromObj with the correct signature. I didn't find any extension using Ttk_GetOrientFromObj.

Copyright

This document has been placed in the public domain.