Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What do the parentheses around a function name mean?

People also ask

What is in the parenthesis of a function?

Parentheses have multiple functions relating to functions and structures. They are used to contain a list of parameters passed to functions and control structures and they are used to group expressions to control the order of execution.

What is parentheses in function call?

When we call a function with parentheses, the function gets execute and returns the result to the callable. In another case, when we call a function without parentheses, a function reference is sent to the callable rather than executing the function itself.

What do you call the variables inside the parenthesis of a function?

'the formal variables inside the function parantheses' are also known as parameters . When you say why aren't they declared, you mean why aren't they declared with the keyword var . (Example: var myVariable = 4646; ).


In the absence of any preprocessor stuff going on, foo's signature is equivalent to

int foo (int *bar)

The only context in which I've seen people putting seemingly unnecessary parentheses around function names is when there are both a function and a function-like macro with the same name, and the programmer wants to prevent macro expansion.

This practice may seem a little odd at first, but the C library sets a precedent by providing some macros and functions with identical names.

One such function/macro pair is isdigit(). The library might define it as follows:

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

/* the function */
int (isdigit)(int c) /* avoid the macro through the use of parentheses */
{
  return isdigit(c); /* use the macro */
}

Your function looks almost identical to the above, so I suspect this is what's going on in your code too.


The parantheses don't change the declaration - it's still just defining an ordinary function called foo.

The reason that they have been used is almost certainly because there is a function-like macro called foo defined:

#define foo(x) ...

Using (foo) in the function declaration prevents this macro from being expanded here. So what is likely happening is that a function foo() is being defined with its body being expanded from the function-like macro foo.