Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.c > #15704

Re: Macro for pthread_create()

From jt@toerring.de (Jens Thoms Toerring)
Newsgroups comp.lang.c
Subject Re: Macro for pthread_create()
Date 2012-01-10 21:03 +0000
Organization Freie Universitaet Berlin
Message-ID <9n3ndtFrrU1@mid.uni-berlin.de> (permalink)
References <87d3arv2ns.fsf@father.nostromo.wy> <9n3gahF6uvU1@mid.uni-berlin.de> <9n3koiFctkU1@mid.uni-berlin.de> <0.c61077dd9cdc25f73003.20120110202912GMT.87mx9vqp2f.fsf@bsb.me.uk>

Show all headers | View raw


Ben Bacarisse <ben.usenet@bsb.me.uk> wrote:
> jt@toerring.de (Jens Thoms Toerring) writes:
> <snip>
> >> daniele.g <daniele@father.nostromo.wy> 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?
> <snip>
> > 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).

> It's as old as C89 ("ANSI C")

Thanks, had somehow associated it with C99.

> and you've got a typo in the macro.  You presumable wanted
> to write:
>   #define THREAD(func,parm) \
>           pthread_create(&func ## _id, NULL, func, (void *)parm)

Uups, yes, of course! I thought I had copy-and-paste'd it from
my test program but I seem to have screwed that up:-(

                         Best regards, Jens
-- 
  \   Jens Thoms Toerring  ___      jt@toerring.de
   \__________________________      http://toerring.de

Back to comp.lang.c | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread


Thread

Macro for pthread_create() daniele@father.nostromo.wy (daniele.g) - 2012-01-10 19:21 +0100
  Re: Macro for pthread_create() jt@toerring.de (Jens Thoms Toerring) - 2012-01-10 19:02 +0000
    Re: Macro for pthread_create() jt@toerring.de (Jens Thoms Toerring) - 2012-01-10 20:18 +0000
      Re: Macro for pthread_create() Ben Bacarisse <ben.usenet@bsb.me.uk> - 2012-01-10 20:29 +0000
        Re: Macro for pthread_create() jt@toerring.de (Jens Thoms Toerring) - 2012-01-10 21:03 +0000
  Re: Macro for pthread_create() James Kuyper <jameskuyper@verizon.net> - 2012-01-10 14:14 -0500
    Re: Macro for pthread_create() Seebs <usenet-nospam@seebs.net> - 2012-01-10 20:44 +0000
    Re: Macro for pthread_create() Anand Hariharan <mailto.anand.hariharan@gmail.com> - 2012-01-13 07:18 -0800
  Re: Macro for pthread_create() Seebs <usenet-nospam@seebs.net> - 2012-01-10 19:15 +0000
    Re: Macro for pthread_create() daniele@mother.nostromo.wy (daniele.g) - 2012-01-10 23:01 +0100
      Re: Macro for pthread_create() Ben Bacarisse <ben.usenet@bsb.me.uk> - 2012-01-10 22:23 +0000
        Re: Macro for pthread_create() Keith Thompson <kst-u@mib.org> - 2012-01-10 15:23 -0800
      Re: Macro for pthread_create() jt@toerring.de (Jens Thoms Toerring) - 2012-01-10 22:27 +0000
        Re: Macro for pthread_create() Keith Thompson <kst-u@mib.org> - 2012-01-10 15:25 -0800
      Re: Macro for pthread_create() Eric Sosman <esosman@ieee-dot-org.invalid> - 2012-01-10 17:31 -0500
        Re: Macro for pthread_create() daniele@mother.nostromo.wy (daniele.g) - 2012-01-11 00:04 +0100
          Re: Macro for pthread_create() James Kuyper <jameskuyper@verizon.net> - 2012-01-10 18:17 -0500
          Re: Macro for pthread_create() Eric Sosman <esosman@ieee-dot-org.invalid> - 2012-01-10 18:29 -0500
      Re: Macro for pthread_create() Ian Collins <ian-news@hotmail.com> - 2012-01-11 11:54 +1300
        Re: Macro for pthread_create() daniele@father.nostromo.wy (daniele.g) - 2012-01-11 10:09 +0100
          Re: Macro for pthread_create() Ian Collins <ian-news@hotmail.com> - 2012-01-11 22:20 +1300
          Re: Macro for pthread_create() James Kuyper <jameskuyper@verizon.net> - 2012-01-11 11:26 -0500
            Re: Macro for pthread_create() daniele@father.nostromo.wy (daniele.g) - 2012-01-12 12:07 +0100
              Re: Macro for pthread_create() James Kuyper <jameskuyper@verizon.net> - 2012-01-12 09:19 -0500
                Re: Macro for pthread_create() Eric Sosman <esosman@ieee-dot-org.invalid> - 2012-01-12 20:34 -0500
            Re: Macro for pthread_create() daniele@father.nostromo.wy (daniele.g) - 2012-01-12 11:52 +0100
          Re: Macro for pthread_create() Seebs <usenet-nospam@seebs.net> - 2012-01-11 18:46 +0000
            Re: Macro for pthread_create() blp@cs.stanford.edu (Ben Pfaff) - 2012-01-11 11:12 -0800

csiph-web