foodic said:
Hi all,
I am new to C programming. I have seen in many Source
files a declaration as follows,
typedef void iamafresher(int x, int y);
why they use typedef with function.
Beginners often use typedef too much. The point with typedef,
is mainly to increase the readability of your code. A typedef
don't define a new type, it's just an alias.
Typdef's can be overdone! This may be such a case... because
struct foo1
{
void (*iamaf) (int x, int y);
};
and
struct foo1
{
iamafresher *iamaf;
};
is different ways to say the _same_ thing. Experienced C
programmers prefer to declare struct foo1 the first way,
because that doesn't hide the fact that 'iamaf' is a
function.
The declaration of the signal function in the standard, is
quite complex:
void (*signal (int sig, void (*func) (int sig))) (int sig);
So what does this really mean? Well, with a typedef
it's much easier to understand:
typedef void signal_handler(int);
signal_handler *signal(int sig, signal_handler *func);