On Wednesday, 20 August 2014 at 07:02:52 UTC, blake kim wrote:
On Wednesday, 20 August 2014 at 06:17:43 UTC, Dominikus Dittes
Scherkl wrote:
On Wednesday, 20 August 2014 at 06:11:42 UTC, blake kim wrote:
But I don't think this is right. Many C APIs need structure
as argument and adjusting align each structure doesn't make
sense.
Is this problem a Bug of D ?
Default alignment in D is pointersize (size_t) - so 8 on 64bit.
But most C compilers default to 4 regardless of pointersize.
I think this is more a bug in C than in D.
epoll_wait is a system API on Linux.
So, I can't agree that it is a bug of C in alignment.
C uses 4 byte alignment, then, I think, it is sensible that D
should follow that.
Actually, In core.sys.linux.epoll.d, struct epoll_event
doesn't assign a specific align so that the problem is caused.
I found the solution.
This is a obvious bug of core.sys.linux.epoll.d.
The default alignment of all of both C and D is 8 on 64bit OS.
But epoll_event is packed as
follows.(/usr/include/x86_64-linux-gnu/sys/epoll.h)
struct epoll_event
{
uint32_t events; /* Epoll events */
epoll_data_t data; /* User data variable */
} __attribute__ ((__packed__));
Therefore, epoll_event should be declared in D as follows.
extern(C) align(1) struct epoll_event {
align(1):
uint events;
epoll_data_t data;
}