cfunctionfunction-pointers

C compilation error "called object is not a function or function pointer"


I got a snippet of C code from online, and I am trying to compile it. I am getting the following error.

error: expected declaration specifiers or '...' before ')' token
    6 | extern FUNC(void, MY_CODE) MyLatestUpdate()(void);
      |                          ^
ERROR!
/tmp/RkrMFH0deT.c: In function 'main':
/tmp/RkrMFH0deT.c:11:41: error: called object is not a function or function pointer
   11 | #define STD_ON                          1u
      |                                         ^~

Below is the snippet of the code

In .h file

#define MY_CODE

extern FUNC(void, MY_CODE) MyLatestUpdate()(void);

In another .h file

#define MyLatestUpdate()    MyPreValue()
#define MyPreValue()        UPDATE_VALUE
#define UPDATE_VALUE        STD_ON
#define STD_ON              1u

in .c file

int main() {
    // Write C code here
    MyLatestUpdate()();
    printf("test code");
    return 0;
}

Seems like I am getting the error in the .h file

extern FUNC(void, MY_CODE) MyLatestUpdate()(void);

error: expected declaration specifiers or '...' before ')' token

Is the function declared as a function pointer or a function macro? How can I resolve these issues? Any help


Solution

  • MyLatestUpdate is turned into 1u by the preprocessor. You try to compile

    extern FUNC (void, ) 1u()(void);
    

    Which is complete nonsense.