简体   繁体   中英

Why is C telling me I need a pointer to a function for my MSP430

I am using the following code:

#include <msp430.h>

int flip(int flip){
    if (flip) {flip = 0;}
    else {flip = 1;}
    return flip;
}

/*...*/

void main(void){
    int ctrl = 0;
    while(1){
        ctrl = flip(ctrl);
    }
}

When I attempt to compile I get the error, referring to the line:

ctrl = flip(ctrl);

error #110: expression preceding parentheses of apparent call must have (pointer-to-) function type

I don't understand why the compiler is giving me this error.

Replies are correct: the compiler doesn't like it when I'm using the same name for a variable and a function. Fixed.

The compiler is getting confused because, in your context, flip refers both to a function and to an int . You should change the name of the argument to something else.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM