[Up: Using C++ objects with Tcl]
[Previous: Contents] [Next: The C++ Domain]

Introduction

A major feature of the Tcl language is its extensibility using C functions, further enhanced by the introduction of dynamically loadable modules. Two philosophies exist for mixing Tcl and C. The first is to have a C application which just uses an integrated Tcl interpreter to execute rather small scripts that affect the applications runtime behavior. The other is to use Tcl as the glue to compose and control individual and rather independent modules into a larger application. While the focus of the C++ language is certainly on the second principle, this package makes sense in both cases.

This document is not an introduction into C++ or Tcl, but assumes that you are quite fluent in both languages. It helps if you have already played around with C-language extensions to Tcl and dynamic loading.

The code is still in experimental stages, and changes take place on a regular basis, usually requiring more or less changes in class implementations as well. Some portability problems exist; each new system holds its own surprises, mainly due to linking problems. If you can't handle a few problems yourself, this package is probably not (yet) for you. See the later chapters and the distribution's README file for some hints if things go wrong.

The documentation is in a similarly rough stage. So let's make this quick and have a look at the package's features and problems (apart from what's been mentioned in the abstract) in loose order.

+
No code changes. While code must be added, you do not need to browse through thousands of lines of existing code to look for incompatibilities. And you only need to touch classes that you actually want to be manipulated from the Tcl level.
+
Overloading, virtual functions and abstract base classes. These three major principles of object-oriented programming are fully supported from the Tcl level. Base class's operations are visible in derived classes unless they are overloaded. The new operator refuses to instantiate objects of an abstract class, yet an abstract class can still provide some common functionality.
+
Polymorphism. You can pass an object as a parameter to a function that actually expects a base class.
-
Code additions. For each class, you must provide a special constructor and a member function mainly to map the string arguments of a Tcl function call to their proper types.
+
The writing of these two functions is made as easy as possible by macros, many helper functions and a type checker that checks a function call's arguments against a custom table, so that you do not need to do error checking on this part but can simply assume that all arguments have the correct type.
-
No multiple inheritance. You can derive a class from two or more base classes, but only one direction of inheritance can be made visible on the Tcl level.
-
No conversions in argument passing. While C++ compilers can detect that they can cast an object to the argument's expected type, this is not (yet) supported on the Tcl level (excluding the special case of polymorphism).
-
Arguments are always passed by-reference, and objects can only be returned by-reference.
-
No direct access to data members or static functions.

See the discussion of the example classes for more information.


[Previous: Contents] [Next: The C++ Domain]
[Up: Using C++ objects with Tcl]

Frank Pilhofer
Wed Mar 12 14:37:08 MET 1997