typedef and declaration of function

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Ron Natalie

    #16
    Re: typedef and declaration of function


    "Vu Pham" <vu@sivell.co m> wrote in message news:bu4b4v$do1 q2$1@ID-219297.news.uni-berlin.de...
    [color=blue]
    >
    > I use c++ for the implementation file, but that function needs to be
    > exported ( from an.so ) and I use extern "C" { } in the declaration file (
    > .h ) to prevent the name mangling.[/color]

    extern "C" doesn't change the language. Only the linkage. In C++ that's
    a function with no arguments.

    Comment

    • Nick Hounsome

      #17
      Re: typedef and declaration of function


      "Vu Pham" <vu@sivell.co m> wrote in message
      news:bu4dee$dui pe$1@ID-219297.news.uni-berlin.de...[color=blue]
      >
      > "Ron Natalie" <ron@sensor.com > wrote in message
      > news:400565ec$0 $71404$9a6e19ea @news.newshosti ng.com...[color=green]
      > >
      > > "Vu Pham" <vu@sivell.co m> wrote in message[/color]
      > news:bu49bv$ddd ep$1@ID-219297.news.uni-berlin.de...[color=green][color=darkred]
      > > >
      > > > Is there any difference between these two declarations :
      > > >
      > > > 1.
      > > > void * functionA( char * p, int s, int * e );
      > > >
      > > > and
      > > > 2.
      > > > typedef void * ( *functionA_t)( char * p, int s, int * e );
      > > > functionA_t functionA();[/color]
      > >
      > > Yes, the second defines a function called functionA that returns a[/color][/color]
      pointer[color=blue][color=green]
      > > to function. functionA_t is type pointer to function.
      > >
      > > You could
      > > typedef void (functionA_t) (char*, int, int*);
      > > functionA_t functionA; // note no parens.
      > >[/color]
      >
      > Thanks, Ron. I think you mean
      >
      > typedef void* (functionA_t) (char*, int, int*);[/color]

      Or even just
      typedef void* functionA_t(cha r*,int,int*);

      But note that you cannot use the typedef to define the function:

      functionA_t f; // OK decl
      functionA_t f { } // ill formed defn


      Comment

      Working...