• 13
• 18
• 19
• 27
• 9

# slimdx reinterpret_cast use

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

## Recommended Posts

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.