Thread: Passing the address of a function to a function.

  1. #1
    Registered User
    Join Date
    Sep 2015
    Posts
    22

    Passing the address of a function to a function.

    Hi

    I'm new to C and I'm trying to modify some existing code to use command line parameters in place of global constants. I've coded and debugged the parameter passing but I'm struggling to modify the existing code to accept parameters to some functions.

    This line...

    wiringPiISR (Parameters.GPIO_A, INT_EDGE_BOTH, &encoderPulse(Parameters));

    generates the following warning and error:

    NewIQ_rot.c:286:49: warning: taking address of expression of type 'void'
    wiringPiISR (Parameters.GPIO_A, INT_EDGE_BOTH, &encoderPulse(Parameters));
    ^
    NewIQ_rot.c:286:49: error: lvalue required as unary '&' operand

    The carat symbol aligns with the &.

    Parameters is the data structure that contains the command line parameters. The encoderPulse function used to be just encoderPulse() but I want to pass it the data structure. wiringPiISR is from an external library found here...

    WiringPi

    I'm confused and would be grateful for any help.

  2. #2
    Registered User
    Join Date
    Feb 2012
    Posts
    347
    Is it possible to show the code

  3. #3
    Registered User
    Join Date
    Sep 2015
    Posts
    22
    Quote Originally Posted by Satya View Post
    Is it possible to show the code
    Hi Satya.

    The function is:

    Code:
    void encoderPulse(struct paramList Encoder)
    {
    
    
            if ( inCriticalSection == TRUE ) return;
            inCriticalSection = TRUE;
    
    
            int MSB = digitalRead(Encoder.GPIO_A);
            int LSB = digitalRead(Encoder.GPIO_B);
    
    
            int encoded = (MSB << 1) | LSB;
            int sum = (lastEncoded << 2) | encoded;
    
    
            if(sum == 0b1101 || sum == 0b0100 || sum == 0b0010 || sum == 0b1011) encoderPos++;
            else if(sum == 0b1110 || sum == 0b0111 || sum == 0b0001 || sum == 0b1000) encoderPos--;
    
    
            lastEncoded = encoded;
            inCriticalSection = FALSE;
    }
    The entire code is here ... NewIQ_rot.c. It is very much work in progress. Thanks.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Passing variable from function - main - function
    By ulti-killer in forum C Programming
    Replies: 2
    Last Post: 11-01-2012, 12:14 PM
  2. Passing address or pointer as argument to function
    By Edelweiss in forum C Programming
    Replies: 7
    Last Post: 08-17-2011, 12:38 AM
  3. Passing address to a function, Problems !
    By WarDoGG in forum C Programming
    Replies: 4
    Last Post: 07-10-2008, 03:58 PM
  4. Replies: 1
    Last Post: 09-04-2007, 10:00 PM
  5. Passing an address to a function
    By Vicious in forum C++ Programming
    Replies: 5
    Last Post: 09-12-2004, 12:05 PM