솔라리스 10 인텔버전에서 gcc 컴파일을 했는데 에러가 계속 나네요 조언좀 부탁합니다.
#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 > 블럭 안에 넣어주세요 - 스페이스는 빼고 입력하세요
코드를 올리실때는 < c o d e > < / c o d e > 블럭 안에 넣어주세요 - 스페이스는 빼고 입력하세요
---------------------------------------------------------------------------------------------------------
이 댓글(comment)의 수정 및 삭제를 위해 이 글에 답글(reply)를 달지말고 원 글에 댓글(comment)로 달아주세요
-------------------------------------------------------------------------------
이 댓글(comment)의 수정 및 삭제를 위해 이 글에 답글(reply)을 쓰지 말아 주십시요.
의견이 있으시면 원 글에 댓글(comment)로 써 주세요.
음...
정말 아주 매우 특이한 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 』
음.. 예전 c언어 스타일을 흉내 내려다 이렇게 된거 아닌가요?
예전 c언어 스타일에서는
함수의 인자형을 괄호안에 쓰지 않고, 그 다음줄에 표시하는데...
중괄호 안에 넣는것이 아니라.. 함수명 바로 아래에 적습니다.
질문자께서는 중괄호 안에다가 인자형을 지정하셨더군요...
요즘은 그렇게 안쓰는 분위기 임으로 함수명에 바로 인자의 형을 지정하시기 바랍니다.
process_join(nproc,id) // 부모프로세스가 자식프로세스의 작업이 종료될때까지 // 대기한다. { int *nproc, *id; ... } process_join(int * nproc,int *id) // 부모프로세스가 자식프로세스의 작업이 종료될때까지 // 대기한다. { ... }댓글 달기