slimdx reinterpret_cast use

Started by
0 comments, last by jpetrie 14 years, 1 month ago
I notice SlimDX uses reinterpret_cast a lot to go between managed structures and the native equivalents. For example:

pin_ptr<VertexElement> pinnedElements = &elements[0];
                IDirect3DVertexDeclaration9* decl;

                HRESULT hr = device->InternalPointer->CreateVertexDeclaration( reinterpret_cast<const D3DVERTEXELEMENT9*>( pinnedElements ), &decl );
                
Is this always safe? I mean it makes sense that the bits would be the same, but since native C++ doesn't guarantee the byte sizes of primitives, could it break someday? For example, if the managed structure uses System::Int32 which matches the bit size of a native C++ int on Windows, but what if someday a native C++ int became 64 bits? This doesn't bother me, but I just wanted to verify that the code is making an assumption of the byte sizes of the native types for this to work.
-----Quat
Advertisement
Yes, we're relying on compiler-, platform- and API-specific behavior, including the default alignment and packing rules and the memory layouts used for the pinned managed types.

This topic is closed to new replies.

Advertisement