Sign in to follow this  

slimdx reinterpret_cast use

This topic is 2817 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 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.

Share this post


Link to post
Share on other sites

This topic is 2817 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.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this