| | |
Howmany byte is pointer?
Please support our C++ advertiser: Intel Parallel Studio Home
![]() |
>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
>It's so simple: exactly
How do you propose this to be meaningful for pointers to functions?
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?
I'm here to prove you wrong.
•
•
Join Date: Aug 2008
Posts: 83
Reputation:
Solved Threads: 18
The size of a pointer has to be consistent for a particular system. It is the reason for labeling a system as 32-bit, 64-bit, etc. The reason for having different types of pointers is for the allocation of memory at that particular location, and to help prevent buffer overflows when passing a pointer.
http://bytes.com/groups/c/216087-size-sizeof-pointer
not nececerially. there is no default pointer size, just the actual size it is. If there were, it would imply that you could
somehow specify any size you wished. No mention of a default size is mentioned in the C spec.
There is no guarantee that all pointer types will have the same sizeeither (except in the case of pointers to structures and unions).
e.g an int* may be larger than a char*. This is particuarly true with regards to function pointers and data pointers, which are, for example, different sizes from each other in DOS depending on which memory model is used. For example, the AS/400 PS by IBM specifies additional informationb with regards to function pointers whioch can make it significantly bigger than an ordinary data pointer.
However, On most modern OS platforms and Compilers, all pointer types are of equal size and are reprsesneted in the same way on a low level.
In most cases, word length / register size of the processor (CPU) determines the size of a pointer which is generally 2 or 4 or 8 bytes for 16,32 and 64 bit CPUs respectively, but as i said, you should never assume this to always be the case. Thats why the size of a pointer determines the maximum memory that can be
addressed at once e.g the 4gb limit on 32 bit systems.
•
•
•
•
The size of a pointer has to be consistent for a particular system. It is the reason for labeling a system as 32-bit, 64-bit, etc. The reason for having different types of pointers is for the allocation of memory at that particular location, and to help prevent buffer overflows when passing a pointer.
somehow specify any size you wished. No mention of a default size is mentioned in the C spec.
There is no guarantee that all pointer types will have the same sizeeither (except in the case of pointers to structures and unions).
e.g an int* may be larger than a char*. This is particuarly true with regards to function pointers and data pointers, which are, for example, different sizes from each other in DOS depending on which memory model is used. For example, the AS/400 PS by IBM specifies additional informationb with regards to function pointers whioch can make it significantly bigger than an ordinary data pointer.
However, On most modern OS platforms and Compilers, all pointer types are of equal size and are reprsesneted in the same way on a low level.
In most cases, word length / register size of the processor (CPU) determines the size of a pointer which is generally 2 or 4 or 8 bytes for 16,32 and 64 bit CPUs respectively, but as i said, you should never assume this to always be the case. Thats why the size of a pointer determines the maximum memory that can be
addressed at once e.g the 4gb limit on 32 bit systems.
Last edited by jbennet; Dec 1st, 2008 at 1:09 pm.
If i am helpful, please give me reputation points.
•
•
•
•
>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 besizeof p, where p is defined as the pointer one wants to test.
>It's so simple: exactlysizeof(void*).
How do you propose this to be meaningful for pointers to functions?
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.
>The size of a pointer has to be consistent for a particular system.
Correct, but keep in mind that T* is a completely different type from U*, assuming T and U don't map to the same type. You seem to be pretending that all pointers have the same type (a universal pointer type), which is false.
>It is the reason for labeling a system as 32-bit, 64-bit, etc.
An xx-bit system is where xx is the number of bits that can be processed in parallel. Usually this means the data bus of the CPU, not the size of pointers in the addressing system.
>because it's possible to assign arbitrary pointer type value (including
>function pointers) to the void* type variable and get back the original value
That's incorrect. A pointer to void is defined to work only with object types, not function types. It's not safe to assign the address of a function to a pointer to void.
>Don't tread on me with member pointers
I'm not quite that pedantic.
Correct, but keep in mind that T* is a completely different type from U*, assuming T and U don't map to the same type. You seem to be pretending that all pointers have the same type (a universal pointer type), which is false.
>It is the reason for labeling a system as 32-bit, 64-bit, etc.
An xx-bit system is where xx is the number of bits that can be processed in parallel. Usually this means the data bus of the CPU, not the size of pointers in the addressing system.
>because it's possible to assign arbitrary pointer type value (including
>function pointers) to the void* type variable and get back the original value
That's incorrect. A pointer to void is defined to work only with object types, not function types. It's not safe to assign the address of a function to a pointer to void.
>Don't tread on me with member pointers
I'm not quite that pedantic.
I'm here to prove you wrong.
![]() |
Other Threads in the C++ Forum
- Previous Thread: Connecting to a php file
- Next Thread: virtual class with friend functions
| Thread Tools | Search this Thread |
api array arrays based beginner binary c++ c/c++ calculator char char* class classes code compile compiler console conversion count delete deploy desktop directshow dll download dynamic dynamiccharacterarray encryption error file forms fstream function functions game givemetehcodez google graph gui homeworkhelp homeworkhelper iamthwee ifstream input int integer java lib linkedlist linker linux list loop looping loops map math matrix memory news number numbertoword output parameter pointer problem program programming project python random read recursion recursive reference return rpg sorting string strings struct temperature template templates test text text-file tree unix url variable vector video visual visualstudio win32 windows winsock wordfrequency wxwidgets






