What's the use of multiple asterisks in the function call? What's the use of multiple asterisks in the function call? c c

What's the use of multiple asterisks in the function call?


One of the standard conversions, in both C and C++, is the function-to-pointer conversion; when a function name appears in an expression, it can be converted into a pointer to that function. So:

  • foo is equivalent to &foo
  • *foo is equivalent to *(&foo), or foo
  • **foo is eqivalent to **(&foo), or *foo, or foo

and so on.

This means that you can legally add as many * as you like before a function name without changing its meaning. There's no reason to do that, though.


Why is this thing allowed both in C and C++?

I can't speak for C++, but for C at least a function designator is converted to a pointer:

6.3.2.1 - 4

A function designator is an expression that has function type. Except when it is the operand of the sizeof operator or the unary & operator, a function designator with type ‘‘function returning type’’ is converted to an expression that has type ‘‘pointer to function returning type’’.

Applying the indirection operator yields a function designator:

6.5.3.2 - 3

The unary * operator denotes indirection. If the operand points to a function, the result is a function designator

So no matter how many times you apply the indirection operator you'll get the same thing: a function designator that's immediately converted to a pointer.


In my opinion there's little or no use in doing this.


Because the * operator expects an address value. And whenever a value is expected (as opposed to an object or function glvalue), the lvalue to rvalue, function to pointer and array to pointer conversions are applied on an operand. So the dereferenced function immediately again converts to a pointer when again dereferenced.

These all either read values from objects or produce a pointer value that refers to the beginning of an array or function respectively.

These rows of dereferences have no purpose other than for the lulz of it.