This might be rather simple but I have a method that expects a parameter to be of type
BYTE **Ptr
And for various reasons I am using an int* (we’ll call intPtr for this example) in the code that will call this method, so I was wondering if it is safe to do this:
MethodCall((BYTE**) &intPtr, ...
The method locks an image buffer in place and you supply a BYTE* to it so that once it has locked the buffer it sets the pointer to point to the start of the locked buffer in memory. This is part of the Windows Media Foundation code and so cannot be easily changed to suit my int*.
Will the casting above do the job of having my intPtr still point to the locked buffer memory address after the call, as if it were a BYTE* as requested. Also, is there any danger to doing this?
In general, this is not “safe”. Whilst a pointer-to-
Tmay be converted to a pointer-to-Uand back again, modifying it via the pointer-to-Uis, at best, implementation-defined.In your example, the method will modify your
int *to point at some memory, but there’s no guarantee that that it will choose some memory that is correctly aligned forint. This would lead to what’s known as “a big mess”.