Why is this code parentheses on both sides of the function name?

Asked 2 years ago, Updated 2 years ago, 147 views

I found this C function in the project source file

int (foo) (int *bar)
{
    return foo (bar);
}

At first, I thought it was a function point, but it wasn't either Why is it covered in parentheses?

function c parenthese

2022-09-22 22:20

1 Answers

If I hadn't pre-processed it, int (foo) (int *bar) is the same as int foo(int *bar).

I'm not sure there's an entire source code, Usually parentheses the function name to prevent the macro from expanding when the function and the macro have the same name

/* macro */
#define isdigit(c) ...

/* /* function */
int (isdigit)(intc) // use parentheses to distinguish from macros. Higher Priority
{
  return isdigit(c); // using macros
}


2022-09-22 22:20

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.