Results 1 to 3 of 3

Thread: Why these warnings?

  1. #1

    Thread Starter
    Fanatic Member
    Join Date
    Feb 2003
    Location
    C:\Windows\Microsoft.NET\Framework
    Posts
    574

    Why these warnings?

    I am practicing function pointers. Here's what I am doing: passing a function pointer to another function. It all goes well except for the two warnings I get:


    [list=1][*]'ConsumeFnPointer' : too many actual parameters[*]declared formal parameter list different from definition[/list=1]


    I am curious as to why I get those warnings. Can we not pass variable arguments to the right of the function pointer argument? Has it got something to do with the calling sequence (__stdcall, ___pascal etc.)?

    Here's the code:

    Code:
    #include <stdio.h>
    
    /*float Add(float, float);
    float Subtract(float, float);
    float Multiply(float, float);
    float Divide(float, float);
    float (*ptr)(float, float);
    */
    
    int DoSomething(int, int);
    int ConsumeFnPointer(int (*ptr1)(int, int));
    
    int main()
    {
    	//ptr=&Add;
    	//printf("%f",ptr(3,9));
    	printf("%d", ConsumeFnPointer(&DoSomething,12,4));
    
    }
    
    /*float Add(float a, float b) { return a+b;}
    float Subtract(float a, float b){ return a-b;}
    float Multiply(float a, float b){ return a*b;}
    float Divide(float a, float b){ return a/b;}
    */
    
    int ConsumeFnPointer(int (*ptr1)(int a, int b), int a, int b)
    {
    	return (*ptr1)(a,b);
    }
    
    int DoSomething(int a, int b)
    {
    	return 1+a-b;
    }

  2. #2
    Kitten CornedBee's Avatar
    Join Date
    Aug 2001
    Location
    In a microchip!
    Posts
    11,594
    The prototype and the definition of ConsumeFnPointer don't match.
    All the buzzt
    CornedBee

    "Writing specifications is like writing a novel. Writing code is like writing poetry."
    - Anonymous, published by Raymond Chen

    Don't PM me with your problems, I scan most of the forums daily. If you do PM me, I will not answer your question.

  3. #3

    Thread Starter
    Fanatic Member
    Join Date
    Feb 2003
    Location
    C:\Windows\Microsoft.NET\Framework
    Posts
    574
    Yup! Thanks! Just saw that a moment after making that post.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width