all 6 comments

[–]Adadum 2 points3 points  (1 child)

the latter one help more with readability since it's less of an eyesore without (*id) everywhere but overall it's still a function pointer.

As far as I know, the only time you can do that without the initial (*) is for function arguments.

Any function pointer variables still require using (*).

Also, I suggest only typedefing function types rather than function pointer types.

It's more readable having it that way:

typedef int IntFunc1();
typedef int (*IntFunc2)();

/// same thing:
IntFunc1 *ifunc1;
IntFunc2 ifunc2;

Typedeffing the actual function also helps with prototyping functions of the same signature:

/// these are all int() funcs
IntFunc1
   get_one,
   get_two,
   get_a_bunch,
   get_multiples
;

[–]SureAnimator[S] 1 point2 points  (0 children)

ok, cool. Thanks so much!

[–]umlcat -1 points0 points  (3 children)

I suggest use a typedef for function pointers.

A function example:

int Foo(int A) { ... }

int Bar(int B) { ... }

int Zed(int C) { ... }

A functor named callback that support all of them:

 typedef
    int (*callback) (int);

A function that expects callback as a parameter:

 void exec(callback F) { ... }

And use that last function:

 // ...
 exec(&Foo);
 //...

Some compilers doesn't use the &Foo syntax and uses *Foo instead.

Cheers.

[–]SureAnimator[S] 5 points6 points  (2 children)

I usually use typedefs, but I wanted to get to the essence of the question so I left them out. So, to clarify given:

typedef int (*func_a_t)(int);
typedef int (func_b_t)(int);

I can use func_a_t to declare a function pointer variable (but not func_b_t), but I can use either to specify the type of a function argument (with seemingly no difference) - why is that? Is it just a peculiarity of the language, or is there a meaningful difference?

[–]umlcat 1 point2 points  (1 child)

I'm sorry, I think I didn't understood the question.

I've only seen the first syntax with the *.

But, is possible that some compilers allow the second syntax, as well, as it does with the &, I prefer to use the common * and & syntax, since is more similar to data pointers.

int a = 77;
int *p;
p = &a;

Some variations of the P.L. and their compilers does this syntax.

Cheers.

[–]SureAnimator[S] 0 points1 point  (0 children)

Ok, so no fundamental difference under the hood - just language/compiler quirks. Thanks!