-
Declaration confusion
Hi all
I'm learning to use Direct3D and DirectX at the moment, and I've come across a piece of code I'm a little confused by, could anyone clarify what the below is doing:
(BYTE**) &pVertices // pVertices is a void pointer
I can see roughly the effect it is having on the program, however I'm a little confused as to what it's actually doing. Any help would be appreciated cheers! :)
-
It's taking the address of pVerticies, making the value a pointer to a pointer. It's then saying that this pointer to a pointer is not void **, but BYTE ** instead. I'd need more context to know why it's doing that. Perhaps the code is passing the pointer into a function by reference so changes to it can be returned to the caller?
-
pointers to pointers always confuse me lol
-
Its basically casting the void pointer to a byte pointer. But since your getting the address of pVertices which is already a pointer, the value returned would be a pointer to a pointer. Hence you need to cast it to a pointer to pointer to byte.
-
Pointers to pointers need not confuse you.
Say, you have an int. To modify it, you need to pass a pointer to the int to a function.
Now say you have a pointer to int (int*). To modify it, you need to pass a pointer to that variable; thus it becomes a pointer to (the) pointer to int.
First case:
Variable to modify: int x;
Argument by function: int * px;
Second case:
Variable to modify: int * x;
Argument by function: int* * px;
Simple, really.