void type?

Started by
12 comments, last by pulpfist 17 years, 11 months ago
i am confused with this code. VOID* pVertices; if( FAILED( g_pVB->Lock( 0, sizeof(Vertices), (void**)&pVertices, 0 ) ) ) why woud you need to recast (void**)&pVertices why not just this as I don't see why the recasting is needed ()&pVertices
Advertisement
Maybe because VOID isn't the same type as void.
"Debugging is twice as hard as writing the code in the first place. Therefore, if you write the code as cleverly as possible, you are, by definition, not smart enough to debug it." — Brian W. Kernighan
It's not needed in this case. But usually pVertices will be a pointer to your own vertex type. Then you'd need a cast.

Just asking, correct me if I'm wrong, isn't a pointer conversion to void always legal ?
Quote:Original post by jagguy
i am confused with this code.

VOID* pVertices;
if( FAILED( g_pVB->Lock( 0, sizeof(Vertices), (void**)&pVertices, 0 ) ) )

why woud you need to recast
(void**)&pVertices

why not just this as I don't see why the recasting is needed
()&pVertices


The cast is from void* to void**, ie from a pointer-to-void to a pointer-to-pointer-to-void, hence the & taking the address of the pointer-to-void.

HTH Paul
Well to be sure ud have to give us the definition of the Lock() function.

I don't see why casting to void* would be illegal, its a neutral pointer type.

If your compiler gives cast warnings it means you might be doing something you don't want to do, so that's why it's better to do an explicit cast.

Quote:Original post by ronkfist
Well to be sure ud have to give us the definition of the Lock() function.

I don't see why casting to void* would be illegal, its a neutral pointer type.

If your compiler gives cast warnings it means you might be doing something you don't want to do, so that's why it's better to do an explicit cast.


It is not casting to void*, it is casting to void**. This is a different type.
Quote:Original post by EasilyConfused
Quote:Original post by ronkfist
Well to be sure ud have to give us the definition of the Lock() function.

I don't see why casting to void* would be illegal, its a neutral pointer type.

If your compiler gives cast warnings it means you might be doing something you don't want to do, so that's why it's better to do an explicit cast.


It is not casting to void*, it is casting to void**. This is a different type.


I was replying to this...
Quote:isn't a pointer conversion to void always legal

I'm not entirely sure if the question has been answered yet, but I compiled this with Dev-C++ (MinGW), and it didn't give me any warnings:
 void *a; void **b=&a a=b;

"void*" can take any pointer type.
But, if you replace "a=b" with "b=a", it will tell you that there is an invalid conversion from "void*" to "void**". So "void**" can not take any arbitrary pointer type.
Projects:> Thacmus - CMS (PHP 5, MySQL)Paused:> dgi> MegaMan X Crossfire
I am not really sure i still get this.

q) Is a VOID the same as void?

q) if you look at this in terns of an array. A
VOID* pVertices; //is an array

(void**)&pVertices //is a pointer to pointer like a 2-d array so you are re-casting this as another data type, so why not cast is as this
VOID** pVertices; //initially

it looks like we are giving space for an 1-D array then changing it to a 2-D array, that's why it look odd to me.

This topic is closed to new replies.

Advertisement