sizeof(void *)*1

Started by
3 comments, last by dnagcat 21 years, 1 month ago
could somebody please explain this to me sizeof(void *)*1 Thanks
Advertisement
You''re taking the sizeof() a pointer, which is 4 bytes on 32-bit machines. The multiplication by one yields 4, and so your final answer is 4 bytes. The result would be the same if you took the sizeof() any type of pointer since all pointers are of the same size under a specific machine architecture.

RapscallionGL - arriving soon.
________________________________________________"Optimal decisions, once made, do not need to be changed." - Robert Sedgewick, Algorithms in C
void* is a pointer and thus 4 (in bytes) (unless you are on a 64 bit system or something but im sure you arent) and *1 would not do anything since thats an identity operation or whatever its called.

it evaluates to 4.
(http://www.ironfroggy.com/)(http://www.ironfroggy.com/pinch)
OK...so this makes sense
memset(TextureImage, 0, sizeof(void *)*1);
TextureImage is a pointer so what your doing here is clearing memory for the pointer to 0 by the size of a pointer, right?
quote:Original post by johnnie2
The result would be the same if you took the sizeof() any type of pointer since all pointers are of the same size under a specific machine architecture.
Not true!

In the days of 16 bit Intel machines, there were near and far pointers. I believe near pointers were 16 bits and far pointers were 32.

Also, in C++, pointers to member functions in certain circumstances can be represented in a manner different than normal machine level pointers. For example, I just wrote a small test program using VC++ 6 that prints the sizeof a pointer to a member of a class that virtually inherits a base class. The result is 12 instead of the usual 4.

Regarding the topic at hand, my guess is that the unnecessary *1 was added to "clarify" that initializing only one element was the intent.

This topic is closed to new replies.

Advertisement