On Tuesday, 23 July 2013 at 15:24:39 UTC, Kagamin wrote:
On Saturday, 20 July 2013 at 04:18:41 UTC, Chad Joan wrote:
If there are still things that you (community inclusive) are
afraid of missing, then I am pretty willing to do C99 instead
and skip C89.
A standard _Align attribute? You need it, right?
I didn't know that was standard in C99.
I'm looking through ISO/IEC 9899:1999 (n1256) and not finding it.
That'd be cool to know about; any chance you can point it out?
At any rate, I'm actually not sure if you mean member alignment
or memory alignment, but I'm pretty sure both are doable using
char pointer arithmetic and casting.
Hmmm, member alignment would be annoying, but still doable:
// D
struct Foo
{
align(1):
ubyte a;
ushort b;
ubyte c;
}
int main()
{
Foo f;
f.a = 1;
f.b = 2;
f.c = 3;
return 1;
}
/* C89 */
int main()
{
char f[4];
*((uint8_t*)(f+0)) = 1;
*((uint16_t*)(f+1)) = 2;
*((uint8_t*)(f+3)) = 3;
return 1;
}
Caveat: untested code written in a couple minutes.