함수 호출에 관해서 질문이요~~
글쓴이: leo~~~~ / 작성시간: 목, 2005/09/29 - 11:42오전
예를 들어서요
void func(com *x, int m)
이러한 함수를 선언하고 메인에서 이 함수를
호출하려고 하는데요... com은 구조체 이구요...
typedef struct {
double real, imag;
} com;
구조체는 이렇게 되어 있구요....
메인에서 어떻게 호출해야 하나요??
main()
{
void( ???, 10);
}
이렇게 하믄 될것 같은데요....
???이 부분을 어떻게 해야할지를 모르겠어요....
윽...포인터....ㅜ.ㅜ
Forums:


[code:1]main() { void&#
main() { void( ???, 10); }main() { com a; /* your codes ...... */ func(&a, 10); }그렇게 했는데요.....parse error numeric const
그렇게 했는데요.....
parse error numeric constant
이런에러가 뜨네요....ㅡ,.ㅡ;;;
source를 올려 보십시요.
source를 올려 보십시요.
이게 소스 인데요......fft(고속푸리에 변환) 소스 입니다...
이게 소스 인데요......fft(고속푸리에 변환) 소스 입니다...
이 소스를 분석해달라는게 아니구요......
def.c 코드에 보시면 main() 함수가 없자나요....
main 함수를 만들어야 하는데요.....
메인에서 fft 함수를 호출하도록이요.....
계속 이렇게도 해보고 저렇게도 해봤는데 에러가 나서요....
부탁드립니다..
============def.h=====================
typedef struct { double real, imag; } COMPLEX; #define PI 3.141592 void fft(COMPLEX *,int); void ifft(COMPLEX *,int); void dft(COMPLEX *,COMPLEX *,int); void idft(COMPLEX *,COMPLEX *,int); void rfft(double *,COMPLEX *,int); void ham(COMPLEX *,int); void han(COMPLEX *,int); void triang(COMPLEX *,int); void black(COMPLEX *,int); void harris(COMPLEX *,int); int log2(unsigned int);==============def.c================
#include <math.h> #include <stdlib.h> #include <stdio.h> #include "dft.h" void fft(COMPLEX *x, int m) { static COMPLEX *w; static int mstore = 0; static int n = 1; COMPLEX u,temp,tm; COMPLEX *xi,*xip,*xj,*wptr; int i,j,k,l,le,windex; double arg,w_real,w_imag,wrecur_real,wrecur_imag,wtemp_real; if(m != mstore) { if(mstore != 0) free(w); mstore = m; if(m == 0) return; n = 1 << m; le = n/2; w = (COMPLEX *) calloc(le-1,sizeof(COMPLEX)); if(!w) { printf("\nUnable to allocate complex W array\n"); exit(1); } arg = PI/le; wrecur_real = w_real = cos(arg); wrecur_imag = w_imag = -sin(arg); xj = w; for (j = 1 ; j < le ; j++) { xj->real = (double)wrecur_real; xj->imag = (double)wrecur_imag; xj++; wtemp_real = wrecur_real*w_real - wrecur_imag*w_imag; wrecur_imag = wrecur_real*w_imag + wrecur_imag*w_real; wrecur_real = wtemp_real; } } le = n; windex = 1; for (l = 0 ; l < m ; l++) { le = le/2; for(i = 0 ; i < n ; i = i + 2*le) { xi = x + i; xip = xi + le; temp.real = xi->real + xip->real; temp.imag = xi->imag + xip->imag; xip->real = xi->real - xip->real; xip->imag = xi->imag - xip->imag; *xi = temp; } wptr = w + windex - 1; for (j = 1 ; j < le ; j++) { u = *wptr; for (i = j ; i < n ; i = i + 2*le) { xi = x + i; xip = xi + le; temp.real = xi->real + xip->real; temp.imag = xi->imag + xip->imag; tm.real = xi->real - xip->real; tm.imag = xi->imag - xip->imag; xip->real = tm.real*u.real - tm.imag*u.imag; xip->imag = tm.real*u.imag + tm.imag*u.real; *xi = temp; } wptr = wptr + windex; } windex = 2*windex; } j = 0; for (i = 1 ; i < (n-1) ; i++) { k = n/2; while(k <= j) { j = j - k; k = k/2; } j = j + k; if (i < j) { xi = x + i; xj = x + j; temp = *xj; *xj = *xi; *xi = temp; } } }[/code]header filename이 def.h인데 def.c 에서 dft.h
header filename이 def.h인데 def.c 에서 dft.h file을 include하고 있습니다.
제가 def.c의 dft.h include부분을 def.h로 고치고 make할때 math library를 link하도록 -lm option을 주어 compile하니 실행파일은 만들어지는군요.
함수호출
함수 호출할때 배열을 넘겨보세요.
예를 들면.
int main() { COMPLEX com[1024]; fft(com,8); }컴파일 옵션은 위에 쿨링팬님이 말씀하신것처럼 -lm 하시면
돌아갑니다..
헛...제가 오타를 냈군요....죄송합니다......ㅡ,.ㅡ;;;
헛...제가 오타를 냈군요....
죄송합니다......ㅡ,.ㅡ;;;
dft가 맞는거구요.....^^
moonzoo님 말씀대로 배열을 넘기니까
됩니다~~감사합니다~~~^^
아....근데요....moonzoo님 왜 배열로 해야하는거죠???
아....근데요....
moonzoo님 왜 배열로
해야하는거죠????
[quote="Anonymous"]아....근데요....moonzoo
void fft(COMPLEX *x, int m) 함수에서
x가 쓰인곳은 총 4군데 인데 다음과 같이 쓰였습니다.
포인터 주소인 x 에 + 되어진 주소값을 참조하려면
x가 배열일 것이라 생각되었습니다.
아......그렇군요~~감사합니다~~ㅋ
아......그렇군요~~
감사합니다~~ㅋ
댓글 달기