-
-
Notifications
You must be signed in to change notification settings - Fork 1.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
alignOf, offsetOf for C based backends #5493
Comments
Well it turns out that I hate my hack a lot. I implement these features now with macros. My macro implementation will definitively have it's limitations but I think the part that I need will be possible to implement. Sad thing is, I also need to implement sizeof, because sizeof only works for primitive types at compile time. It seems like I can't statically get the size of composed types. type
MyType = object
a,b: int
const
mysize1 = sizeof(type(MyType))
mysize2 = sizeof(type(array[0 .. 7, byte]))
mysize3 = sizeof(type(tuple[a,b: char])) |
I think you should patch the compiler. |
I implemented |
@krux02 would |
@timotheecour Well, it really looks like I finally have to put a bit of work in this again. The implementation with macros is not really up to date anymore. There is a PR for the compiler. But think your for trying to help out. I think I really have to work on this again. |
I could not find anything in the standard library, therefore I am writing it here.
http://en.cppreference.com/w/cpp/language/alignof
http://www.cplusplus.com/reference/cstddef/offsetof
https://golang.org/pkg/unsafe/#Alignof
There is a way to hack the support of offsetof into my own library with this code snippet:
But I think it should be in the standard library. It is also very important to have a working version of it for example when working with OpenGL, it is needed to pass an array of structs as attributes to the shader
Edit:
Unfortunately the above version is not sufficient for me anymore. I am generating shader code at compile time. I need to be able to generate blocks like the following at compile time from object type definitions:
The above version of offsetof can only be evaluated at runtime, and therefore does not work in this context.
Edit2:
Well, what a hack, but I am impressed that it works so well (so far) for my use case.
The text was updated successfully, but these errors were encountered: