솔라리스 10 인텔버전에서 gcc 컴파일을 했는데 에러가 계속 나네요 조언좀 부탁합니다.

redfoxkiller의 이미지

#include
#include
#include
#include // 두 프로세스간의 상호통신하기 위해 사용
#include // 프로세스간의 자원이 공유될때 발생하는 문제 해결을 위해
// 세마포어 사용을 위한 헤더파일
#include // 프로세스간의 메모리 공유를 위한 헤더파일

int sum;
int process_fork(nproc) // 자식 프로세스를 생성, 자식프로세스의 id값을 반환
{
int *nproc;
int j;
for(j=1;j<=(*nproc)-1;j++)
if(fork()==0)
return(j);
return(0);
}

process_join(nproc,id) // 부모프로세스가 자식프로세스의 작업이 종료될때까지
// 대기한다.
{
int *nproc, *id;
int i;
if (*id==0)
for(i=1;i<=(*nproc)-1;i++)
wait(0);
else exit(0);
}

char *sshared(size, shmid) // 자식 프로세스와 자원 공유
{
int size, *shmid;
char *shmid(), *ptr;
*shmid=shmget(IPC_PRIVATE, size, 0666|IPC_CREAT);
ptr=shmat(*shmid,0,0);
return(ptr);
}

cleanup_memory(shmid) // 자식 프로세스가 사용한 공유자원을 해제
{
int *shmid;

struct shmid_ds *huf;
shmctl(*shmid,IPC_RMID, buf);
}

spin_lock_init(lok,condition) // 세마포어 임계구역에 대한 lock을 초기화
{
int *lok,condition;
int control;
*lok=semget(IPC+PRIVATE,1,0666|IPC_CREAT); // semget 세마포어 집합에 필요한
// 세마포어의 갯수를 나타낸다.
if(condition==0) control=1;
else control=0;
semctl(*lok,0,SETVAL,&control);
}
/*
semctl(semaphore control operations)표준 IPC, 단일 세마포어 연산, 전체 세마포어 연산을 위한 함수
*/

spin_lock(lok) // 임계구역을 lock 시킴
{
int *lok;
struct sembuf operations; // sembuf 세마포어에 대해 수행할 연산을 지정
operations.sem_num=0; // semnum 집합내의 세마포어에 대한 첨자를 지정한다.

operations.sem_op=(-1); // sem_op는 함수 semop이 수행해야 하는 기능을
// 정수로서 나타낸다.
// op값이 음수이므로 일반적인 세마포어 명령 P() 수행
operations.sem_flg=0; // 세마포어 operation flag
semop(*lok,operations,1); // semop 기본적인 세마포어 연산을 수행할 시스템 호출
}

spin_unlock(lok) // 임계구역을 unlock 시킴
{
int *lok;
struct sembuf operations;
operations.sem_num=0;
operations.sem_op=1; // 일반적인 세마포어 명령 V() 수행
operations.sem_flg=0;
semop(*lok,operations,1);
}

void main()
{
int i, x, n, *ptr1,*ptr2, lock, unlock;
int nproc, id, temp, process_fork();
char *sshared();
scanf("%d %d", &x,&n); // 정수와 정수의 지수승을 입력
int sum=0;
temp=1;
ptr1=(int *)sshared(4,&sum); // char형 sshared를 int형으로 형변환
ptr2=(int *)sshared(4,&lock);
nproc=n+1;
spin_lock_init(ptr2, &unlocked); // spin_lock을 초기화
id=process_fork(&nproc);
if (id!=0) // 반복문을 이용하여 temp에 partial result값을 저장
for(i=1;i<=id;i++)
temp=temp*x;
else temp=1;
printf("\n\n\n ID NUMBER : 2%d PARTIAL RESULT : %7\n", id, temp);
spin_lock(ptr2); // 다른 프로세스가 못들어오게 lock
*ptr1 = *ptr1 + temp; // partial sum값을 저장
printf(" ID NUMBER : 2%d PARTIAL SUM : %7d\n", id, *ptr1);
spin_unlock(ptr2); // lock을 풀어준다.
process_join(&nproc, &id);
cleanup_memory(&sum);
cleanup_memory(&lock);
printf("\n\n\n n n-1 n-2 2\n");
printf(" F(X)= X + X + X + X +1 \n\n\n");
printf("\n\n\n **** THE RESULT ****\n\n");
printf(" X = %d n = %d\n\n",x,n);
printf(" f(x) = %d\n", *ptr1);
}
--------------------------------------------------------------------------------------------------------
이소스를 gcc로 컴파일을 하면

# gcc AAA.C
AAA.C: In function `int main()':
AAA.C:11: error: too many arguments to function `char* sshared()'
AAA.C:15: error: at this point in file
AAA.C:11: error: too many arguments to function `char* sshared()'
AAA.C:16: error: at this point in file
AAA.C:18: error: `unlocked' was not declared in this scope
AAA.C:18: error: `spin_lock_init' was not declared in this scope
AAA.C:10: error: too many arguments to function `int process_fork()'
AAA.C:19: error: at this point in file
AAA.C:24: error: `spin_lock' was not declared in this scope
AAA.C:25: error: `process_join' was not declared in this scope
AAA.C:26: error: `cleanup_memory' was not declared in this scope
AAA.C: At global scope:
AAA.C:34: error: `nproc' was not declared in this scope
AAA.C:35: error: expected `,' or `;' before "int"
AAA.C:36: error: expected unqualified-id before '{' token
AAA.C:42: error: expected constructor, destructor, or type conversion before '(' token
AAA.C:44: error: expected unqualified-id before '{' token
AAA.C:50: error: `size' was not declared in this scope
AAA.C:50: error: `shmid' was not declared in this scope
AAA.C:51: error: initializer expression list treated as compound expression
AAA.C:51: error: expected `,' or `;' before "int"
AAA.C:52: error: expected unqualified-id before '{' token
AAA.C:57: error: expected constructor, destructor, or type conversion before '(' token
AAA.C:59: error: expected unqualified-id before '{' token
AAA.C:62: error: expected constructor, destructor, or type conversion before '(' token
AAA.C:64: error: expected unqualified-id before '{' token
AAA.C:70: error: expected constructor, destructor, or type conversion before '(' token
AAA.C:72: error: expected unqualified-id before '{' token
AAA.C:78: error: expected constructor, destructor, or type conversion before '(' token
AAA.C:80: error: expected unqualified-id before '{' token

이렇게 에러가 나옵니다. 뭐가 잘못 됐는지 조언좀 부탁합니다.

블루스크린의 이미지

코드를 올리실때는 < c o d e > < / c o d e > 블럭 안에 넣어주세요 - 스페이스는 빼고 입력하세요
---------------------------------------------------------------------------------------------------------
이 댓글(comment)의 수정 및 삭제를 위해 이 글에 답글(reply)를 달지말고 원 글에 댓글(comment)로 달아주세요

-------------------------------------------------------------------------------
이 댓글(comment)의 수정 및 삭제를 위해 이 글에 답글(reply)을 쓰지 말아 주십시요.
의견이 있으시면 원 글에 댓글(comment)로 써 주세요.

ymir의 이미지

정말 아주 매우 특이한 convention 이네요...
parameter type 을 function 안에서 선언하고, function prototype 마저도...
필요한 function 내부에서 선언해 놓고 쓰시니...

main 안에 보시면... sshared 에 대해 아래와 같이 선언해 놓으셨군요..
char *sshared();

당연히 parameter 를 주고 호출을 하면, 초장부터 에러 만발입니다..
AAA.C:11: error: too many arguments to function `char* sshared()'

아무래도.. 코드를 다시 작성해 보시는게 좋을 것 같군요..
간단한 C 문법책이라도 참조해 보시구요...

되면 한다! / feel no sorrow, feel no pain, feel no hurt, there's nothing gained.. only love will then remain.. 『 Mizz 』

되면 한다! / feel no sorrow, feel no pain, feel no hurt, there's nothing gained.. only love will then remain.. 『 Mizz 』

bejoy4him의 이미지

예전 c언어 스타일에서는
함수의 인자형을 괄호안에 쓰지 않고, 그 다음줄에 표시하는데...
중괄호 안에 넣는것이 아니라.. 함수명 바로 아래에 적습니다.
질문자께서는 중괄호 안에다가 인자형을 지정하셨더군요...

요즘은 그렇게 안쓰는 분위기 임으로 함수명에 바로 인자의 형을 지정하시기 바랍니다.

process_join(nproc,id) // 부모프로세스가 자식프로세스의 작업이 종료될때까지
// 대기한다.
{
    int *nproc, *id;
     ...
}
 
process_join(int * nproc,int *id) // 부모프로세스가 자식프로세스의 작업이 종료될때까지
// 대기한다.
{
 
     ...
}

댓글 달기

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
이것은 자동으로 스팸을 올리는 것을 막기 위해서 제공됩니다.