Forum Discussion
Altera_Forum
Honored Contributor
15 years agotypedef int64_t netbsd32_int64 __attribute__((__aligned__(4)));
Certainly works to give a 64bit int with 4 byte alignment. The same is used elsewhere to generate 2-byte aligned 32bit quantities. Note that if you copy the address to any pointer variable, that must be a pointer to the constrained type. I wouldn't use a loop, just do the shifts and ors - you don't want the loop overheads. There is another gotcha as well, recent gcc (probably 4.something) will track the alignment constraints through certain casts. Since the C language doesn't allow you to generate misaligned pointers to aligned types (and the only valid used of void * require you to cast the pointer back to its original type), it will assume that pointers are aligned. This means the following won't work.void fn(struct foo *fp)
{
struct foo f;
memcpy(&f, fp, sizeof f);when the input pointer might be msialigned. The compiler will inline memcpy() and optimise for aligned pointers.