union variable error(storage size isn't known) - Linux

This is a discussion on union variable error(storage size isn't known) - Linux ; union semun semun0; semun0.val=1; There is an error when compiling, that is like below. storage size of 'semun0' isn't known...

+ Reply to Thread
Results 1 to 2 of 2

Thread: union variable error(storage size isn't known)

  1. union variable error(storage size isn't known)

    union semun semun0;
    semun0.val=1;

    There is an error when compiling, that is like below.
    storage size of 'semun0' isn't known

  2. Re: union variable error(storage size isn't known)

    Ronald wrote:
    > union semun semun0;
    > semun0.val=1;


    > There is an error when compiling, that is like below.
    > storage size of 'semun0' isn't known


    Then you probably have forgotten to include the header file where
    the union is defined. Or it's not defined anywhere and you have to
    define it yourself.

    Since I guess it's about shared memory and you might be reading
    Stevens APUE: The prototype for the semctl() function has been
    changed since the time APUE was published, it's prototype is
    now

    int semctl(int semid, int semnum, int cmd, ...);

    and the semun union isn't defined in anymore - the
    newer POSIX standards actually discourages implementations from
    defining it. You have to define it yourself like this:

    #if defined ( _SEM_SEMUN_UNDEFINED )
    union semun {
    int val; /* value for SETVAL */
    struct semid_ds *buf; /* buffer for IPC_STAT, IPC_SET */
    unsigned short int *array; /* array for GETALL, SETALL */
    struct seminfo *__buf; /* buffer for IPC_INFO */
    };
    #endif

    (If you want to follow the POSIX standard you should leave out the
    last, '__buf' pointer, that's Linux specific.)

    The test of _SEM_SEMUN_UNDEFINED is there to get the program to
    compile also on rather old Linux versions where the semun union
    still was defined in the headers.

    Regards, Jens
    --
    \ Jens Thoms Toerring ___ jt@toerring.de
    \__________________________ http://toerring.de

+ Reply to Thread