char buf[BUF_LEN]_attribute_((aligned(4)));
ssize_t len, i = 0;
/* read BUF_LEN bytes' worth of events */
len = read (fd, buf, BUF_LEN);
/* loop over every read event until none remain */
while (i < len) {
struct inotify_event *event =
(struct inotify_event *) &buf[i];
Monitoring File Events | 239
printf ("wd=%d mask=%d cookie=%d len=%d dir=%s\n",
event->wd, event->mask,
event->cookie, event->len,
(event->mask & IN_ISDIR) ? "yes" : "no");
/* if there is a name, print it */
if (event->len)
printf ("name=%s\n", event->name);
/* update the index to the start of the next event */
i += sizeof (struct inotify_event) + event->len;
}
最佳答案
char buf[BUF_LEN]_attribute_((aligned(4)));
它指定变量 buf
的最小对齐方式,以字节为单位。
它会导致编译器在 4 字节边界上分配变量 buf
。
This 应该是一本好书。
关于c - 第一行的 '_attribute_((aligned(4)));'是什么意思?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7055495/