Why the size of a pointer to a function is different from the size of a pointer to a member function?

Viewed 8906

Isn't a pointer just an address? Or I'm missing something?

I tested with several types of pointers:

  • pointers to any variables is the same (8B on my platform)
  • pointers to functions are the same size, as pointers to variables (8B again)
  • pointers to functions with different parameters - still the same (8B)

BUT pointers to member functions are bigger - 16B on my platform.

Three things:

  1. Why are pointers to member functions bigger? What more information do they need?
  2. As far as I know, the standard says nothing about the size of a pointer, except that void* must be able to "contain" any pointer type. In other words, any pointer must be able to be casted to void*, right? If so, then why sizeof( void* ) is 8, while sizeof a pointer to member function is 16?
  3. Are there any other examples for pointers, that are with different size (I mean, for standard platforms, not some rare and special ones)?
5 Answers
Related