[IPC] 세마포어에서 컴파일시 에러..

initiative의 이미지

아래 코드는 semaphore 를 이용하여 테스트하는 간단한 프로그램입니다.
joinc 위키에서 퍼온 것임.
제 linux 환경(gcc 3.X) 에서 컴파일하는 데

 
[dev@XXXsrc]$ gcc -o orig sem_test_orig.c
sem_test_orig.c:16: error: two or more data types in declaration of `semid'

에러가 납니다.
무엇이 문제인지요?

#include <sys/types.h>
#include <sys/sem.h>
#include <sys/ipc.h>
#include <stdio.h>
#include <unistd.h>

#define SEMKEY 2345

union semun
{
	int val;
	struct semid_ds *buf;
	unsigned short int *array;
}

static int semid;

int main(int argc, char **argv)
{
	FILE* fp;
	char buf[11];
	char count[11];

	union semun sem_union;

	struct sembuf mysem_open ={0, -1, SEM_UNDO};
	struct sembuf mysem_close = {0, 1, SEM_UNDO};
	int sem_num;

	memset(buf, 0x00, 11);
	memset(count, 0x00, 11);

	if(argc > 1) sem_num = 1;
	else sem_num =0;

	semid = semget((key_t)234, sem_num, 0660| IPC_CREAT);
	if(semid == -1)
	{
		perror("semget error");
		exit(0);
	}

	if(semop(semid, &mysem_open, 1) == -1)
	{
		perror("semop error");
		exit(0);
	}

	if( (fp = fopen("counter.txt", "r+")) == NULL)
	{
		perror("fopen error");
		exit(0);
	}

	fgets(buf, 11, fp);
	rewind(fp);

	buf[strlen(buf) -1] = 0x00;

	sprintf(count, "%d\n", atoi(buf) + 1);
	printf("%s", count);

	sleep(10);
	fputs(count, fp);

	fclose(fp);

	semop(semid, &mysem_close, 1);

	return 1;
	
}

[/code]

sangwoo의 이미지

union semun 선언 뒤에 세미콜론이 빠진거 같네요.

----
Let's shut up and code.