세마포 헤더파일 에러

BSK의 이미지

간단한 세마포 프로그램입니다.

파일이름 : pv.h

#include <sys/types.h>
#include <sys/ipc.h>
#include <sys/sem.h>
#include <errno.h>

#define SEMPERM 0600
#define TRUE    1
#define FALSE   0

typedef union_semun {
	int val;
	struct semid_ds *buf;
	ushort *array;
} semun;

int initsem(key_t semkey);
int p(int semid);
int v(int semid);

여기서 union_semun과 관련된 파일은 전부에러로 나오고 있습니다.
의심가는게 #include <sys/sem.h> 인데요.
리눅스에서는 세마포 헤더파일이 다른게 있나요?

에러내용

"pv.h" [변환 되었습니다] 19L, 288C 저장 했습니다
happyguru@happyguru:~/network/sem$ gcc -o testsme testsem.c v.c p.c initsem.c
In file included from testsem.c:1:
pv.h:10: error: syntax error before '{' token
pv.h:14: error: syntax error before '}' token
pv.h:14: warning: data definition has no type or storage class
testsem.c: In function `handlesem':
testsem.c:32: error: syntax error before "pid"
In file included from v.c:1:
pv.h:10: error: syntax error before '{' token
pv.h:14: error: syntax error before '}' token
pv.h:14: warning: data definition has no type or storage class
In file included from p.c:1:
pv.h:10: error: syntax error before '{' token
pv.h:14: error: syntax error before '}' token
pv.h:14: warning: data definition has no type or storage class
In file included from initsem.c:1:
pv.h:10: error: syntax error before '{' token
pv.h:14: error: syntax error before '}' token
pv.h:14: warning: data definition has no type or storage class
initsem.c: In function `initsem':
initsem.c:12: error: syntax error before "arg"
initsem.c:13: error: `arg' undeclared (first use in this function)
initsem.c:13: error: (Each undeclared identifier is reported only once
initsem.c:13: error: for each function it appears in.)

vacancy의 이미지

union_semun 앞에 union 빠진거 아닐까요 .. :oops:

eminency의 이미지

아래는 안 살펴봤지만 일단은...

typedef union_semun {

이게 아니라..

typedef union semun {

이거 아닌가요? 문법 에러부터 찬찬히 살펴 보셔야 할 듯...

노루가 사냥꾼의 손에서 벗어나는 것 같이, 새가 그물치는 자의 손에서 벗어나는 것 같이 스스로 구원하라 -잠언 6:5

익명 사용자의 이미지

BSK wrote:
간단한 세마포 프로그램입니다.

파일이름 : pv.h

#include <sys/types.h>
#include <sys/ipc.h>
#include <sys/sem.h>
#include <errno.h>

#define SEMPERM 0600
#define TRUE    1
#define FALSE   0

typedef union_semun {
	int val;
	struct semid_ds *buf;
	ushort *array;
} semun;

int initsem(key_t semkey);
int p(int semid);
int v(int semid);

여기서 union_semun과 관련된 파일은 전부에러로 나오고 있습니다.
의심가는게 #include <sys/sem.h> 인데요.
리눅스에서는 세마포 헤더파일이 다른게 있나요?

에러내용

"pv.h" [변환 되었습니다] 19L, 288C 저장 했습니다
happyguru@happyguru:~/network/sem$ gcc -o testsme testsem.c v.c p.c initsem.c
In file included from testsem.c:1:
pv.h:10: error: syntax error before '{' token
pv.h:14: error: syntax error before '}' token
pv.h:14: warning: data definition has no type or storage class
testsem.c: In function `handlesem':
testsem.c:32: error: syntax error before "pid"
In file included from v.c:1:
pv.h:10: error: syntax error before '{' token
pv.h:14: error: syntax error before '}' token
pv.h:14: warning: data definition has no type or storage class
In file included from p.c:1:
pv.h:10: error: syntax error before '{' token
pv.h:14: error: syntax error before '}' token
pv.h:14: warning: data definition has no type or storage class
In file included from initsem.c:1:
pv.h:10: error: syntax error before '{' token
pv.h:14: error: syntax error before '}' token
pv.h:14: warning: data definition has no type or storage class
initsem.c: In function `initsem':
initsem.c:12: error: syntax error before "arg"
initsem.c:13: error: `arg' undeclared (first use in this function)
initsem.c:13: error: (Each undeclared identifier is reported only once
initsem.c:13: error: for each function it appears in.)

:oops: 상당히 무안하네요.

요즈음 정신이 없는 상태에서 코딩을 하다보니 에궁 후다닥