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



Ronald <followait@xxxxxxx> 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 <sys/sem.h> 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@xxxxxxxxxxx
\__________________________ http://toerring.de
.



Relevant Pages

  • Re: 64-bit Operarting systems need changes in c programming
    ... An int is 32 bits on my x86-64 Linux system when compiling with GCC. ... long is 64 bits and code and data pointers are 64 bits. ... XSI systems may have an intptr_t declared in stdint.h, but that's not as portable as a union. ...
    (comp.os.linux.misc)
  • (long) An AES implementation for 32-bit platforms
    ... union BLOCK ... needed in the AES algorithm. ... typedef unsigned int word; ... void computetables() ...
    (sci.crypt)
  • Re: Unions Redux
    ... union {int s; unsigned int us;} u; ... depends on the object representation compatibility, ... all to do with the fact that there is a union involved. ... is a trap representation for signed int. ...
    (comp.lang.c)
  • Re: Nesting dis-similar hierarchies
    ... create table Teams(TeamIndex int, ReqTeamName varchar(5), TeamNumber int) ... UNION ... TeamIndex, ReqTeamName, TeamNumber, ...
    (microsoft.public.sqlserver.xml)
  • Re: problem with cast and unions
    ... The part where there is that problem is about conversion from a C float ... to a Small "cell" (actually an int). ... structure, and even then, only if it was NOT the member most recently ... need to declare the union. ...
    (comp.lang.c)