세마포 헤더파일 에러

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: 상당히 무안하네요.

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

댓글 달기

Filtered HTML

  • 텍스트에 BBCode 태그를 사용할 수 있습니다. URL은 자동으로 링크 됩니다.
  • 사용할 수 있는 HTML 태그: <p><div><span><br><a><em><strong><del><ins><b><i><u><s><pre><code><cite><blockquote><ul><ol><li><dl><dt><dd><table><tr><td><th><thead><tbody><h1><h2><h3><h4><h5><h6><img><embed><object><param><hr>
  • 다음 태그를 이용하여 소스 코드 구문 강조를 할 수 있습니다: <code>, <blockcode>, <apache>, <applescript>, <autoconf>, <awk>, <bash>, <c>, <cpp>, <css>, <diff>, <drupal5>, <drupal6>, <gdb>, <html>, <html5>, <java>, <javascript>, <ldif>, <lua>, <make>, <mysql>, <perl>, <perl6>, <php>, <pgsql>, <proftpd>, <python>, <reg>, <spec>, <ruby>. 지원하는 태그 형식: <foo>, [foo].
  • web 주소와/이메일 주소를 클릭할 수 있는 링크로 자동으로 바꿉니다.

BBCode

  • 텍스트에 BBCode 태그를 사용할 수 있습니다. URL은 자동으로 링크 됩니다.
  • 다음 태그를 이용하여 소스 코드 구문 강조를 할 수 있습니다: <code>, <blockcode>, <apache>, <applescript>, <autoconf>, <awk>, <bash>, <c>, <cpp>, <css>, <diff>, <drupal5>, <drupal6>, <gdb>, <html>, <html5>, <java>, <javascript>, <ldif>, <lua>, <make>, <mysql>, <perl>, <perl6>, <php>, <pgsql>, <proftpd>, <python>, <reg>, <spec>, <ruby>. 지원하는 태그 형식: <foo>, [foo].
  • 사용할 수 있는 HTML 태그: <p><div><span><br><a><em><strong><del><ins><b><i><u><s><pre><code><cite><blockquote><ul><ol><li><dl><dt><dd><table><tr><td><th><thead><tbody><h1><h2><h3><h4><h5><h6><img><embed><object><param>
  • web 주소와/이메일 주소를 클릭할 수 있는 링크로 자동으로 바꿉니다.

Textile

  • 다음 태그를 이용하여 소스 코드 구문 강조를 할 수 있습니다: <code>, <blockcode>, <apache>, <applescript>, <autoconf>, <awk>, <bash>, <c>, <cpp>, <css>, <diff>, <drupal5>, <drupal6>, <gdb>, <html>, <html5>, <java>, <javascript>, <ldif>, <lua>, <make>, <mysql>, <perl>, <perl6>, <php>, <pgsql>, <proftpd>, <python>, <reg>, <spec>, <ruby>. 지원하는 태그 형식: <foo>, [foo].
  • You can use Textile markup to format text.
  • 사용할 수 있는 HTML 태그: <p><div><span><br><a><em><strong><del><ins><b><i><u><s><pre><code><cite><blockquote><ul><ol><li><dl><dt><dd><table><tr><td><th><thead><tbody><h1><h2><h3><h4><h5><h6><img><embed><object><param><hr>

Markdown

  • 다음 태그를 이용하여 소스 코드 구문 강조를 할 수 있습니다: <code>, <blockcode>, <apache>, <applescript>, <autoconf>, <awk>, <bash>, <c>, <cpp>, <css>, <diff>, <drupal5>, <drupal6>, <gdb>, <html>, <html5>, <java>, <javascript>, <ldif>, <lua>, <make>, <mysql>, <perl>, <perl6>, <php>, <pgsql>, <proftpd>, <python>, <reg>, <spec>, <ruby>. 지원하는 태그 형식: <foo>, [foo].
  • Quick Tips:
    • Two or more spaces at a line's end = Line break
    • Double returns = Paragraph
    • *Single asterisks* or _single underscores_ = Emphasis
    • **Double** or __double__ = Strong
    • This is [a link](http://the.link.example.com "The optional title text")
    For complete details on the Markdown syntax, see the Markdown documentation and Markdown Extra documentation for tables, footnotes, and more.
  • web 주소와/이메일 주소를 클릭할 수 있는 링크로 자동으로 바꿉니다.
  • 사용할 수 있는 HTML 태그: <p><div><span><br><a><em><strong><del><ins><b><i><u><s><pre><code><cite><blockquote><ul><ol><li><dl><dt><dd><table><tr><td><th><thead><tbody><h1><h2><h3><h4><h5><h6><img><embed><object><param><hr>

Plain text

  • HTML 태그를 사용할 수 없습니다.
  • web 주소와/이메일 주소를 클릭할 수 있는 링크로 자동으로 바꿉니다.
  • 줄과 단락은 자동으로 분리됩니다.
댓글 첨부 파일
이 댓글에 이미지나 파일을 업로드 합니다.
파일 크기는 8 MB보다 작아야 합니다.
허용할 파일 형식: txt pdf doc xls gif jpg jpeg mp3 png rar zip.
CAPTCHA
이것은 자동으로 스팸을 올리는 것을 막기 위해서 제공됩니다.