Jens Thoms Toerring <> wrote:
> daniele.g <> wrote:
> > For code portability I need to write a macro THREAD(func, param) which
> > must be resolved into pthread_create(&func_id, NULL, func, (void *)
> > param)
> > I wrote this:
> > #define THREAD(func,parm) (pthread_create(&func, NULL, func, (void *)
> > parm))
> > But it doesn't work. Any clue?
> pthread_create() takes (at least in the POSIX version) a
> pointer to a pthred_t variable (that can't be NULL and must
> be an address the function can write to) as its first ar-
> gument, not a function (and also not a pointer to the
> pointer to the function to be called). So this macro
> can't "work". And what has using such a macro to do with
> "portability"?
Sorry, I overlooked that it's 'func_id' in what you want the
macro to expand to. With that I can only guess at your inten-
tions: do you always have a variable for the thread ID (i.e.
the first argument) that has the same name as the function,
but with '_id' appended to it? In that case you could try
#define THREAD(func,parm) pthread_create(&#func_id, NULL, func, (void *) parm)
(assuming that your compiler understands the concatenation
bit '##', which is, as far as I remember from C99).
With this
THREAD( a, b )
should expand to
pthread_create(&a_id, NULL, a, (void *) b)
Regards, Jens
--
\ Jens Thoms Toerring ___
\__________________________
http://toerring.de