Re: Invoking a function through function pointer



Peter Nilsson wrote:
> ...
> It's a little known quirk that both C and C++ accept...
>
> #include <stdio.h>
>
> int main(void)
> {
> (***** /*...*/ *****puts)("Hello World!");
> return 0;
> }
>
> Indirection on an expression with function type just produces the
> same function designator.
> ...

.... although the term "function designator" is C-specific. In C++ the
situation is a bit different and, for example, as a consequence of that,
the extra parentheses (with or without '*' inside) will disable
argument-dependent name lookup

namespace test {
struct s {};
void foo(s);
}

int main() {
test::s s;
foo(s); // OK
(foo)(s); // ERROR
(*foo)(s); // ERROR
}

--
Best regards,
Andrey Tarasevich
.



Relevant Pages

  • Re: dereferencing function pointer types
    ... typedef int; ... Dereferencing a function pointer does nothing. ... & (function type expression) ...
    (comp.lang.c)
  • Re: sizeof main;
    ... Vijay Kumar R Zanvar wrote: ... The sizeof operator shall not be applied to an expression that has ... sizeof.c:6: warning: sizeof applied to a function type ... The function main is of 'int ' type, where I am not entirely sure ...
    (comp.lang.c)
  • Re: Haskll type system
    ... 'Int -> ', and it's built and examined using the data constructor ... since T1 is not a function type. ... You can instantiate it by choosing the type of the argument and of ...
    (comp.lang.functional)
  • Re: where is device_get_parent function defined
    ... The function type should be on a ... function(int a1, int a2, float fl, ... I am surprised with this whole 'recursive' issue because in a clean source tree ... run 'make obj' before doing 'make' in modules directories. ...
    (freebsd-current)
  • Call function address stored in type of size_t?
    ... If you try to call the nested function through its address after the ... to some of the variables that are no longer in scope, you may be lucky, ... int main{ ... The called object of type size_t is not a function type. ...
    (comp.lang.c)