View Single Post
Join Date: Jul 2008
Posts: 2,001
Reputation: ArkM has much to be proud of ArkM has much to be proud of ArkM has much to be proud of ArkM has much to be proud of ArkM has much to be proud of ArkM has much to be proud of ArkM has much to be proud of ArkM has much to be proud of ArkM has much to be proud of 
Solved Threads: 343
ArkM's Avatar
ArkM ArkM is offline Offline
Postaholic

Re: Howmany byte is pointer?

 
0
  #9
Dec 1st, 2008
Originally Posted by Narue View Post
>seem it is trick question.
It is a trick question. Not only can the size of a pointer vary depending on the system, the size of pointers to different types aren't required to be the same. The best answer to this question would be sizeof p , where p is defined as the pointer one wants to test.

>It's so simple: exactly sizeof(void*) .
How do you propose this to be meaningful for pointers to functions?
1. The void* type size is the supremum of all pointer type sizes because it's possible to assign arbitrary pointer type value (including function pointers) to the void* type variable and get back the original value. It's impossible to do if sizeof(void*) < sizeof(wide_pointer_type) for wide_pointer_type (set theory).

Of course, a schizophrenical software architect is capable to invent the C or C++ implementation with unused data fields in all pointers except void* ones. Well, let's remember default argument promotion rules and %p format specification. It's too hard job for lunatic to implement all these features with such exotic pointers...

Make a compromise: sizeof(pointer_type) <= sizeof(void*)
2. Don't tread on me with member pointers , otherwise it was an ill-formed question...

3. The only type sizes in C and C++ are introduced via operator sizeof. Strictly speaking any answer without sizeof is incorrect (or the question is ill-formed )...
Last edited by ArkM; Dec 1st, 2008 at 1:53 pm.
Reply With Quote