-
Notifications
You must be signed in to change notification settings - Fork 45
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
Add Support For Alignment Specifier In C Struct Declarations #94
Conversation
Thank you, If you add a test and give the version number a minor bump then we can make a release on Hackage. The last I remember was the the tests were a little tricky, sorry. |
I can't seem to figure out where the test would fit. test/harness/README says that suite is meant for "existing libraries" (which I'm guessing means compiling C libraries from other projects) and harness is for "tests documenting bugs and problems", but I can't seem to find where I would test new features. Should I just put one in harness? I'm kind of new to Haskell and it's testing system tbh. |
Ok, welcome, and no worries, I'll take care of the tests when this is done: I think that this isn't quite correct however. For example it will fail when the alignment specifier is not the first specifier of the first struct member. A careful reading of the C11 standard (draft) actually doesn't allow these on struct members (https://www.open-std.org/jtc1/sc22/wg14/www/docs/n1570.pdf) however this was corrected in a defect report https://www.open-std.org/jtc1/sc22/wg14/www/docs/n2396.htm#dr_444 I would expect that the example here parses, for example: https://en.cppreference.com/w/c/language/_Alignas #include <stdalign.h>
#include <stdio.h>
// every object of type struct sse_t will be aligned to 16-byte boundary
// (note: needs support for DR 444)
struct sse_t
{
alignas(16) float sse_data[4];
};
// every object of type struct data will be aligned to 128-byte boundary
struct data
{
char x;
alignas(128) char cacheline[128]; // over-aligned array of char,
// not array of over-aligned chars
};
int main(void)
{
[printf](http://en.cppreference.com/w/c/io/fprintf)("sizeof(data) = %zu (1 byte + 127 bytes padding + 128-byte array)\n",
sizeof(struct data));
[printf](http://en.cppreference.com/w/c/io/fprintf)("alignment of sse_t is %zu\n", alignof(struct sse_t));
alignas(2048) struct data d; // this instance of data is aligned even stricter
(void)d; // suppresses "maybe unused" warning
} |
Does this library support statements that declare a variable? I can't seem to find anything that would allow it to declare a local variable. |
Hi! Dropping in from outside -- having in |
7157fb1
to
94c0a86
Compare
@noahmartinwilliams could you possibly rebase? |
4c9a730
to
5e49574
Compare
@Bodigrim , ok, rebased. |
@noahmartinwilliams GitHub UI shows me lots of new files, could you please take another look? Were they added by accident? |
@Bodigrim . Huh, that's weird. I could have sworn I only changed a few files. I honestly don't know what to do here. I guess they must have somehow been added by accident. I think I saw some of them that looked like they were from my home directory, so maybe there's a bug in git or github? |
5e49574
to
4665a94
Compare
C Data structures can now be parsed that have the _Alignas and alignas keywords used in it.
The alignas keyword can be used anywhere in a data structure declaration in front of any attribute.
Previously the alignas keywords would only apply alignment to attributes immediately to the right of them and not after them.
No worries, I rebased myself. Thanks! |
@tomsmeding @leftaroundabout before I cut a release of |
The PR ( visq/language-c#94 ) is merged (thanks Bodigrim!) so we can just use that directly.
@Bodigrim Works! Checked a project that indeed fails with language-c from hackage but works with 0.10.0 from master here. |
C Data structures can now be parsed that have the _Alignas and alignas keywords used in it.