Typedef function pointer?

后端 未结 6 2195

I\'m learning how to dynamically load DLL\'s but what I don\'t understand is this line

typedef void (*FunctionFunc)();

I have a few questio

6条回答
  •  孤城傲影
    2020-11-22 03:21

    1. typedef is used to alias types; in this case you're aliasing FunctionFunc to void(*)().

    2. Indeed the syntax does look odd, have a look at this:

      typedef   void      (*FunctionFunc)  ( );
      //         ^                ^         ^
      //     return type      type name  arguments
      
    3. No, this simply tells the compiler that the FunctionFunc type will be a function pointer, it doesn't define one, like this:

      FunctionFunc x;
      void doSomething() { printf("Hello there\n"); }
      x = &doSomething;
      
      x(); //prints "Hello there"
      

提交回复
热议问题