Target support for packed/aligned (1) structs

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



For the usual GNU/Linux targets, does GCC support unaligned loads through pointers to packed structs? That is, something like that:

struct __attribute__ ((may_alias, packed, aligned (1))) header
{
  uint16_t id;
  uint16_t flags;
  uint16_t qdcount;
  uint16_t ancount;
  uint16_t nscount;
  uint16_t adcount;
};

uint16_t
get_question_count (const void *buf)
{
  const struct header *header = buf;
  return ntohs (header->qdcount);
}

And this should work even if buf is not properly aligned.

I know there are problems if I take the address of a member in struct header and use that pointer, but I hope that direct use of the member is okay.

This would allow us to simplify some code in glibc and avoid defensive copies to a properly aligned struct.

Thanks,
Florian



[Index of Archives]     [Linux C Programming]     [Linux Kernel]     [eCos]     [Fedora Development]     [Fedora Announce]     [Autoconf]     [The DWARVES Debugging Tools]     [Yosemite Campsites]     [Yosemite News]     [Linux GCC]

  Powered by Linux