Casting a function pointer to another type

后端 未结 7 1469
终归单人心
终归单人心 2020-11-22 08:07

Let\'s say I have a function that accepts a void (*)(void*) function pointer for use as a callback:

void do_stuff(void (*callback_fp)(void*), vo         


        
7条回答
  •  一整个雨季
    2020-11-22 08:30

    Void pointers are compatible with other types of pointer. It's the backbone of how malloc and the mem functions (memcpy, memcmp) work. Typically, in C (Rather than C++) NULL is a macro defined as ((void *)0).

    Look at 6.3.2.3 (Item 1) in C99:

    A pointer to void may be converted to or from a pointer to any incomplete or object type

提交回复
热议问题