Keith said:
It's a matter of style, and therefore there's no one correct answer.
But if there were
}, it would be that
int *foo(void);
is preferable to
int* foo(void);
Yes, but combining declarations in one line isn't the only reason to
put the "*" with the "int"; it's just the most obvious one. It's the
same declaration-follows-use principle; if we drop the "void", then
int *foo()
means that *foo() is an int (and therefore that foo() is a pointer to
int, and foo is a function returning a pointer to int).
I respect your opinion Keith, but I disagree with this style.
Consider
the following 3 blocks:
void f(int);
void *g(int, int);
int func_returns_int(void);
int **h_int_ptr_ptr(int, int);
struct foo_long_name fln(int, void *);
struct foo_long_name *fln_ptr(int, void *);
BAR gB(int);
BAR *gB_ptr(int);
void f(int);
void *g(int, int);
int func_returns_int(void);
int **h_int_ptr_ptr(int, int);
struct foo_long_name fln(int, void *);
struct foo_long_name *fln_ptr(int, void *);
BAR gB(int);
BAR *gB_ptr(int);
void f(int);
void * g(int, int);
int func_returns_int(void);
int ** h_int_ptr_ptr(int, int);
struct foo_long_name fln(int, void *);
struct foo_long_name *fln_ptr(int, void *);
BAR gB(int);
BAR * gB_ptr(int);
(Which, with variable width fonts all look like crap, but
in the 2nd two, the function names should be vertically aligned.)
When looking at the declaration of a function, I've never
cared about *foo, I've only cared about foo(). I want to
know what the function returns, and I tend to use the
3rd style in a block of function declarations, so that
the return types are easily distinguishable. Now, I'll
readily acknowledge that nearly everyone on this group
has more experience than I, so I'd like to see arguments
against using that 3rd style. (other than the variable
width font issue, which is totally irrelevant AFAIC)
Note: I'm ignoring complex function declarations like
int *(*((*f)(int, int *(*(g)(void *))(void))));
since I have no clue how to declare that in a
stylistically meanigful way other than cleaning it
up with typedefs and macros.