This is the mail archive of the
gcc@gcc.gnu.org
mailing list for the GCC project.
Re: threads in C++
- To: gcc at gcc dot gnu dot org
- Subject: Re: threads in C++
- From: Ross Smith <ross dot s at ihug dot co dot nz>
- Date: Tue, 16 Nov 1999 12:33:08 +1200
- Organization: The Internet Group
- References: <199911152311.PAA14747@kankakee.wrs.com>
Mike Stump wrote:
>
> > Date: Mon, 15 Nov 1999 12:14:22 -0500
> > From: Dima Volodin <dvv@dvv.org>
>
> > > Not necessarily. You could use a static member function. But if you need
> > > to get at object data, you'll have to get that passed in explicitly.
>
> > POSIX doesn't say you can use a "static member function", ergo you
> > can not. If the trick works for g++, it doesn't mean it will work
> > for any other compiler.
>
> They also don't say that you can do with with functions named foo, but
> guess what, you can. Or let me put this another way, C++ guarantees
> that this can be done.
Not quite. C++ does guarantee that a static member function is usable
wherever a global function with the same type can be used. But a thread
function requires (or at least, is allowed to require) C linkage
(because Pthreads are defined in terms of a C interface), and member
functions (static or not) can't have C linkage.
It works on GCC (and many other compilers) because the linker doesn't
distinguish between C and C++ functions apart from name mangling (which
doesn't make any difference here). But that's an artifact of a
particular compilation system, not something you can rely on. (Granted,
it's a very common property; I don't know of any compilers on which it
isn't true. But it's not guaranteed by any of the C, C++, or Posix
standards.)
--
Ross Smith <ross.s@ihug.co.nz> The Internet Group, Auckland, New Zealand
========================================================================
"There are many technical details that make Linux attractive to the
sort of people to whom technical details are attractive." -- Suck