Jump to content
  • Advertisement
Sign in to follow this  
jagguy

void type?

This topic is 4415 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

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

Share this post


Link to post
Share on other sites
Advertisement
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.

Share this post


Link to post
Share on other sites
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

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
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

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!