Thread: Function pointer as the parameter

  1. #1
    Registered User
    Join Date
    May 2005
    Posts
    3

    Question Function pointer as the parameter

    I followed the NAG example for optimation. The main function is:

    void nag_opt_nlp(int n, int nclin, int ncnlin, double a[], int tda, double bl[], double bu[],
    void (*objfun)(int n, double x[], double *objf, double g[], Nag_comm * comm),
    void(*confun)(int n, int ncnlin, int needc[], double x[], double conf[], double conjac[], Nag_Comm *comm),
    double x[], double *objf, double g[],
    Nag_E04_Opt *options, Nag_Comm *comm, NagError *fail)

    In the manual example, the call of the objective function 'objfun' is directly objfun, yet my compiler returns an error of:

    error of parameter 8: can't convert void(int,double [],double *,double [], Nag_comm*) to void(_stdcall *)(int*, double*, double*,double*,Nag_comm*)

    I really have no idea how to tackle this. Anyone can help? Many thanks!

  2. #2
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,661
    Dunno - your error message and code are inconsistent.

    > void (*objfun)(int n, double x[], double *objf, double g[], Nag_comm * comm)
    First parameter is an int in the function pointer declaration in the prototype of nag_opt_nlp

    > can't convert void(int,double [],double *,double [], Nag_comm*)
    What you appeared to try and pass as a parameter matches that.

    > void(_stdcall *)(int*, double*, double*,double*,Nag_comm*)
    What it claimed it wanted doesn't match.
    The first parameter is int*, not int
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

  3. #3
    Registered User
    Join Date
    May 2005
    Posts
    3
    Sorry! Just a typeout error. It is int.

    error C2664: cannot convert parameter 8 from 'void (int, double [], double *, double [], struct comm_struct *)' to
    'void (_stdcall *)(long, double *,double*,double *, struct comm_struct *)'

  4. #4
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,661
    > Sorry! Just a typeout error. It is int.
    Well don't make typo's then!
    Copy/paste what you can actually see.

    Well there's the answer then - one param is int, the other is long.

    Make them consistent.
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. What is a virtual function pointer?
    By ting in forum C++ Programming
    Replies: 4
    Last Post: 03-05-2008, 02:36 AM
  2. Please Help - Problem with Compilers
    By toonlover in forum C++ Programming
    Replies: 5
    Last Post: 07-23-2005, 10:03 AM
  3. pointers
    By InvariantLoop in forum C Programming
    Replies: 13
    Last Post: 02-04-2005, 09:32 AM
  4. structure vs class
    By sana in forum C++ Programming
    Replies: 13
    Last Post: 12-02-2002, 07:18 AM
  5. function pointer & Thread Parameter :: Multithreading
    By kuphryn in forum Windows Programming
    Replies: 3
    Last Post: 09-11-2002, 08:42 AM