What is the size of a general function pointer? The function it is pointing to returns void.
Note: I want to put the function pointer in a 2-d array of chars, so I want to make sure it will be able to fit in there.
What is the size of a general function pointer? The function it is pointing to returns void.
Note: I want to put the function pointer in a 2-d array of chars, so I want to make sure it will be able to fit in there.
Well, putting function pointers in an array of char would be a rather silly thing to do, as it would make much more sense to have an array of function pointers - that way you don't get problems with things that could trip you up. Such as alignment of function pointers that is different from char alignment on certain machines.
However, if you insist of doing silly things, sizeof() will tell you what the size is of a function pointer. Generally it's 1, 2, 4, 8 or 16 bytes - but there's no guarantee for any of those numbers.
Can you explain a bit more why you want to put function pointers in a char-array - it may be that we can come up with a better solution?
--
Mats
Compilers can produce warnings - make the compiler programmers happy: Use them!
Please don't PM me for help - and no, I don't do help over instant messengers.
The sizeof operator can tell you that and it would be either 4 or 8 bytes depending on whether you're using the ILP32 or LP64 model.
If you got a function pointer likethen the size of it isCode:void (*printhello)(void);.Code:sizeof(printhello)
If you have multiple function pointers than the array should be the size of the biggest function pointer.
Vanity of vanities, saith the Preacher, vanity of vanities; all is vanity.
What profit hath a man of all his labour which he taketh under the sun?
All the rivers run into the sea; yet the sea is not full; unto the place from whence the rivers come, thither they return again.
For in much wisdom is much grief: and he that increaseth knowledge increaseth sorrow.
Correct, however, the range of the answer is not limited to 4 or 8 - there are several other possible options - for example we could have a 32-bit segmented X86 model (I know of one compiler that can/could produce such code), in which case a function pointer is 6 bytes (but possibly aligned to 8 bytes), just as an example.
--
Mats
Compilers can produce warnings - make the compiler programmers happy: Use them!
Please don't PM me for help - and no, I don't do help over instant messengers.