Thread: Problem passing a ptr to a fxn into a fxn

  1. #1
    Registered User
    Join Date
    Apr 2004
    Posts
    1

    Problem passing a ptr to a fxn into a fxn

    I am using the wavelet code from numerical recipes in C.
    http://www.library.cornell.edu/nr/bookcpdf/c13-10.pdf
    When I try to call a function that calls another function I get the following error in MS Visual C++:

    wavelet.obj : error LNK2001: unresolved external symbol "void __cdecl wt1(float *,unsigned long,int,void (__cdecl*)(float *,unsigned long,int))" (?wt1@@YAXPAMKHP6AX0KH@Z@Z)
    Debug/w3.exe : fatal error LNK1120: 1 unresolved externals
    Error executing link.exe.


    The relevant code is as follows:

    void daub4(float *, unsigned long, int);
    void wt1(float *, unsigned long, int, void (*)(float [], unsigned long, int));

    void main(){
    ...
    wt1(x, numPoints-1, 1, daub4);
    ...
    }

    void wt1(float a[], unsigned long n, int isign,
    float(*wtstep)(float [], unsigned long, int)){
    //One-dimensional discrete wavelet transform. This routine implements the pyramid algorithm,
    //replacing a[1..n] by its wavelet transform (for isign=1), or performing the inverse operation
    //(for isign=-1)
    //. Note that n MUST be an integer power of 2. The routine wtstep, whose
    //actual name must be supplied in calling this routine, is the underlying wavelet .lter. Examples
    //of wtstep are daub4 and (preceded by pwtset) pwt.
    unsigned long nn;

    if (n < 4) return;
    if (isign >= 0) { //Wavelet transform.
    for (nn=n;nn>=4;nn>>=1) (*wtstep)(a,nn,isign);
    //Start at largest hierarchy, and work towards smallest.
    } else { //Inverse wavelet transform.
    for (nn=4;nn<=n;nn<<=1) (*wtstep)(a,nn,isign);
    //Start at smallest hierarchy, and work towards largest.
    }
    }

    void daub4(float *a, unsigned long n, int isign){
    .......
    .......
    }


    Please help me to pass daub4 into wt1!

    Thanks,
    *Bob_ptr

  2. #2
    Just Lurking Dave_Sinkula's Avatar
    Join Date
    Oct 2002
    Posts
    5,005
    Code:
    void wt1(float *, unsigned long, int, void (*)(float [], unsigned long, int));
    Code:
    void wt1(float a[], unsigned long n, int isign,
             float(*wtstep)(float [], unsigned long, int)) {
    Make the declaration match the definition.
    7. It is easier to write an incorrect program than understand a correct one.
    40. There are two ways to write error-free programs; only the third one works.*

  3. #3
    Code Goddess Prelude's Avatar
    Join Date
    Sep 2001
    Posts
    9,897
    Code tags will make your declaration/definition mismatch problems easier to find. And for those of us that still eyeball the unformatted code, we rarely miss this:
    Code:
    void main(){
    main returns int for the majority of software. If you're giving us code from a freestanding environment then mention it so that we don't jump all over you. Otherwise, you're wrong and we're right.
    My best code is written with the delete key.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. swapping pointers
    By csvraju in forum C Programming
    Replies: 17
    Last Post: 04-01-2009, 03:18 AM
  2. problem with passing value of a function
    By Lince in forum C Programming
    Replies: 7
    Last Post: 02-12-2009, 08:39 AM
  3. Passing Value back problem
    By Unregistered in forum C Programming
    Replies: 10
    Last Post: 05-10-2002, 05:22 PM
  4. Passing the value to the function Problem
    By Unregistered in forum C Programming
    Replies: 4
    Last Post: 05-06-2002, 04:34 AM
  5. problem passing an option as command line argument
    By papous in forum C Programming
    Replies: 3
    Last Post: 11-22-2001, 06:12 PM