Coder Social home page Coder Social logo

Comments (8)

pervognsen avatar pervognsen commented on July 3, 2024 1

Typedefs are just aliases so they're not going to offer type safety on their own. You'll want a struct for each id type, like typedef struct { int32_t id; } sg_buffer;

from sokol.

floooh avatar floooh commented on July 3, 2024

...I guess a better name would simply be sg_buffer, sg_image, etc... without the '_id'

from sokol.

floooh avatar floooh commented on July 3, 2024

done, but I need to figure out how to get the compilers emit warnings when assigning using the wrong type (since everything is uint32_t underneath at least clang doesn't complain when using a sg_image when an sg_buffer is expected, etc...

from sokol.

amerkoleci avatar amerkoleci commented on July 3, 2024

What about typedef handle like vulkan?

from sokol.

floooh avatar floooh commented on July 3, 2024

I'll try this, and also will have a look at the Vulkan headers, thanks!

from sokol.

amerkoleci avatar amerkoleci commented on July 3, 2024

You can use something similar to VK_DEFINE_HANDLE then have the struct implemented per backend, under opengl it would be, for example sg_buffer_id with gl handle and some other props you need.

from sokol.

floooh avatar floooh commented on July 3, 2024

Ok I wrapped the id into a struct, and type checking works now... let's see how (in-)convenient this will be with designed-initialisers though...

from sokol.

floooh avatar floooh commented on July 3, 2024

reminder feedback from @pervognsen:

  • To reply to your final comment (since I can't reply to closed issues): API users shouldn't need to deal with the id fields.

  • Just the structs as a whole. And for sentinels, you can do e.g. #define SG_BUFFER_NONE ((sg_buffer){0}) with C99 compound literals.

from sokol.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.