Jump to content
  • Advertisement
Sign in to follow this  
Quat

slimdx reinterpret_cast use

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

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!