为什么应用程序必须声明 union semun,而不是在 sys/sem.h 中?

Jos*_*ica 5 c posix semaphore unions

POSIX 在该函数的文档semctl中这样说:

类型union semun,应用程序应明确声明:

union semun {
    int val;
    struct semid_ds *buf;
    unsigned short  *array;
} arg;
Run Code Online (Sandbox Code Playgroud)

为什么他们决定应用程序必须声明该联合,而不是仅仅将其放入sys/sem.hglibc FAQ提到也是这种情况,但同样没有说明原因:

sys/sem.h 文件缺少“union semun”的定义。

没有。该联合必须由用户程序提供。以前的 glibc 版本定义了这一点,但这是一个错误,因为在考虑它时它没有多大意义。描述 System V IPC 功能的标准是这样定义的,因此必须采用程序。