On 2005-07-17 05:35:48 +0100, Ian <no***@nowhere.com> said:
verec wrote: On 2005-07-17 03:39:19 +0100, Ian <no***@nowhere.com> said: Why do people keep using static members here when this is plain wrong?
Could you elaborate?
pthread_create is a C function. The third parameter is
void* (*start_routine)(void*)
So when called from C++, this function has the signature
extern "C" void* (*start_routine)(void*)
Which doesn't match a static class member function.
Hmmm. The only thing that would disqualify the static member
in this case is that its linkake is not declared ``extern "C"''.
But if we get down to the spirit of this linkage/ABI requirements
(as opposed to its strict letter), this static member function:
- takes a C style argument (a void *, that cannot be any of the
the more esoteric C++ types (references or polymorphic types)
- returns a C style argument (ditto)
So the only contention point might now reside with name mangling,
and indeed the mom::thread::pthread_main static member appears
as:
__ZN3mom6thread12pthread_mainEPv
I just don't see any _requirement_ in pthread (or anywhere else
for that matter!) that would restrict the kind of name that
a function, (extern "C" or otherwise) must have in order for
the actual link (and further down the road: loading & resolving)
to succeed, provided such a name is what common linkers/loaders
do expect.
Precisely, this whole name mangling business has been invented
by Stroustrup to make sure that linkers/loaders would unwittingly
cooperate.
I would tend to see this whole argument as wrong headed nit-picking,
until proven wrong by an actual refence to the relevant paragraph(s)
of the ISO-C++ document.
Beside this, exiting _practice_ has been using this idiom as far
back as C++ existed, precisely to help map OS defined callbacks
to the "object world of C++". I've been using this since around 1989
(Yep, I'm _that_ old :)
Don't the compiler warnings tell you something?
No. gcc 4.0, -Wall
Well it should!
Again: please quote the standard refence paragraph, and I'm sure
that the GCC developers will be more than willing to adapt.
(And I will be very sorry and will have to go through more convoluted
routes to achieve what is a basically a pointer to standard C function!)
--
JFB