[egcs 1.1.2 mips] union bug ?
Gilles Zunino
Gilles.Zunino@hei.fupl.asso.fr
Sat Apr 17 07:32:00 GMT 1999
Hi,
Let's consider the following code :
%--------------------------------------------------
#include <sys/types.h>
#include <sys/wait.h>
#include <sys/ipc.h>
#include <sys/sem.h>
#include <errno.h>
#include <stdio.h>
int CreateSemaphore(void)
{
int sid;
key_t cle = (getpid() / 100) * 100;
union semun theValue;
int v;
if ((sid = semget(cle,1,IPC_CREAT | 0660)) == -1)
{
perror("CreateSemaphore (semget) ");
exit(errno);
}
theValue.val = 1;
if (semctl(sid,0,SETVAL,theValue) == -1) /* <===== here */
{
perror("CreateSemaphore (semctl) ");
exit(errno);
}
if ((v = semctl(sid,0,GETVAL)) == -1)
{
perror("CreateSemaphore (semctl) ");
exit(errno);
}
printf("Semaphore has value : %d \n",v);
return sid;
}
int main(void)
{
CreateSemaphore();
return 0;
}
%--------------------------------------------------
When compiled with SGI's cc, this code correctly set the
semaphore value to 1.
When compiled with egcs 1.1.2 (mips-sgi-irix6.5) the semaphore
value is left to 0. As far as I understand, the variable "TheValule" :
union semun theValue;
is incorrectly passed to the function semctl().
Here is how gcc was invoked and the gcc version
gcc file.c -g -o file
{dunan ~/} gcc -v
Reading specs from
/usr/local/lib/gcc-lib/mips-sgi-irix6.5/egcs-2.91.66/specs
gcc version egcs-2.91.66 19990314 (egcs-1.1.2 release)
Did I missed something ?
_________________________________________________________________
Gilles Zunino - (Gilles.Zunino@hei.fupl.asso.fr) (A 506) 7636
HEI, 13 rue de Toul, 59 046 LILLE CEDEX FRANCE
Phone : (+33) 3 28.38.48.58 Fax : (+33) 3 28.38.48.04
More information about the Gcc-bugs
mailing list