日期:2014-05-16  浏览次数:20825 次

union semun 变量编译时说大小无法确定,为什么?
我在编译如下代码时,编译器报了一堆错误,其中有一个是“a40.c:28:   错误:‘semopts’   的存储大小未知”,为什么啊:
#include   <sys/types.h>
#include   <sys/ipc.h>
#include   <sys/sem.h>
#include   <sys/shm.h>
#include   <stdio.h>
#include   <stdlib.h>
#include   <string.h>
#include   <signal.h>
#define   SEM_NUM   10
#define   SEM_MODE   (IPC_CREAT|0660)

void   changemode(int   sid,   char   *mode);
void   printfmode   (union   semun   *arg);


void   printfmode   (union   semun   *arg)
{
                printf( "mode=%d:\n ",   arg-> buf-> sem_perm.mode);
                return;
}


int   main(void)
{
                int   semid;
                union   semun   semopts;
                struct   semid_ds   semds;

                if   ((semid=semget(IPC_PRIVATE,   SEM_NUM,   SEM_MODE))==-1)
                {
                                fprintf(stderr,   "semget   error!\n ");
                                exit(1);
                }

                semopts.buf=&semds;
                if((semctl(semid,0,IPC_STAT,semopts))==-1)
                {
                                fprintf(stderr,   "get   semid_ds   error!\n ");
                                exit(1);
                }

                printfmode(&semopts);
                changemode(semid,   "0600 ");


                if((semctl(semid,0,   IPC_STAT,   semopts))==-1)
                {
                                fprintf(stderr,   "get   semid_ds   error!\n ");
                                exit(1);
                }
                printfmode(&semopts);

                if((semctl(semid,0,   IPC_RMID,   0)) <0)
                {
                  &n