c - 第一行的 '_attribute_((aligned(4)));'是什么意思?

标签 c linux

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/

相关文章:

c - 使用#define 定义的数字的平方

c - 当所需的总量未知时,给定时间 malloc 的最佳数量是多少?

linux - 包含变量 shell 脚本的文件

linux - 从批处理中终止交互式程序

C + UNIX,siglongjmp 和 sigsetjmp

c - 如何从存储的字符串数组中使用 getchar() 函数?

c - C/C++ 的独立跨平台 (Windows/Linux) 文件压缩?

c - 'mov' 的内存引用过多

linux - 在哪里可以找到 Linux 全局 mem_map 数组的地址?

android - 与 USB 连接时,ADB 无法识别三星 S21