Oops. I forgot to include compilation guards in ct.h to ensure that
the Cheap Threads functions are declared as extern "C" when you
#include that header in a C++ file.
See the attachment for a slightly revised version of ct.h. Or you
can add the compilation guards yourself:
#ifdef __cplusplus
extern "C"
{
#endif
/* function prototypes here... */
#ifdef __cplusplus
}
#endif
With this change to the header, on my system I could compile cttimer
as a C++ program without alteration.
I will post this revision to the website this weekend.
Another possibility is to skip the compilation guards and compile all
the Cheap Threads modules as C++. I haven't tried it, and you might
need to tweak the code here and there if I left out a necessary
#include or something like that, but it ought to work.
I don't recommend that approach, though. For one thing, future
releases of Cheap Threads will include the compilation guards, so
if you upgrade to a new release you would have to remember to disable
them. Furthermore, compiling everything as C++ is likely to degrade
performance somewhat, at least if you compile with exceptions enabled.
The C++ compiler generates exception handling code that incurs
overhead even when no exceptions occur.
On the other hand you might want exceptions to propagate all the way
up through the scheduler into whatever calls ct_schedule(), so that
each thread doesn't have to include a lot of tedious code to keep
exceptions from escaping. If that's what you want, then you would
have to compile Cheap Threads as C++. Presumably you would be willing
to accept the extra overhead that would result.
Maybe I should make the compilation guards themselves subject to
conditional compilation. Then if you want to compile Cheap Threads
as C++, then you could compile it with CT_PLUSPLUS #defined, and the
compilition guards would be disabled, without your having to edit ct.h.
I'm reluctant to add yet another build option without feedback from
users. Does anybody have any preferences?
Thanks for writing. Please let us know how things turn out.
Scott McKellar mck9@...
http://home.swbell.net/mck9/ct/
Antz wrote:
>
> I've been playing around with the Cheap Threads download package on
> FreeBSD using the GNU C compiler (gcc) and so far it seems great.
> However I really need to use classes and some of the nice data structures
> in C++. Thus far trying to compile the cttimer test program using g++ has
> been utterly impossible.
> Is there any way that the cheap threads code can be used by a program
> written in C++? Or am I going to be forced to use POSIX threads and have
> to write completely different versions of this application for *NIX and
> Windows?
>
> Any help would be greatly appreciated.
> Thnx.
>
> -Antz