467,076 Members | 995 Online
Bytes | Developer Community
Ask Question

Home New Posts Topics Members FAQ

Post your question to a community of 467,076 developers. It's quick & easy.

About typedef -- define the function pointer or define function model?

What's the difference between these two declarations ?

1) typedef void (*pf)(void);
2) typedef void f(void);

the first declaration is define a function pointer, what is the second ?
define a function model?

And can use the second declaration to define a function pointer as follow:

typedef void f(void);
f *pf;

Whether the two declarations of pf1 are both pointer to a function?

1) typedef void (*pf)(void);
pf pf1;
2) typedef void f(void);
f *pf1;

if yes, which is better? and I saw many codes used the second declaration,
what is its' advantage or disadvantage?
Thanks in advance!

ro*********@hotmail.com from china
Apr 21 '06 #1
  • viewed: 9497
Share:
3 Replies
robin liu said:
What's the difference between these two declarations ?

1) typedef void (*pf)(void);
2) typedef void f(void);

the first declaration is define a function pointer,
No, it defines a synonym for an existing function pointer type.
what is the second ? define a function model?
No, it defines a synonym for an existing function type.
And can use the second declaration to define a function pointer as follow:

typedef void f(void);
f *pf;
Yes.
Whether the two declarations of pf1 are both pointer to a function?

1) typedef void (*pf)(void);
pf pf1;
2) typedef void f(void);
f *pf1;
Yes.
if yes, which is better? and I saw many codes used the second declaration,
what is its' advantage or disadvantage?


The advantage of the second is that it does not hide a pointer
characteristic inside a typedef. The * reminds us that here be dragons,
which can be a useful hint. So I use the second form.

--
Richard Heathfield
"Usenet is a strange place" - dmr 29/7/1999
http://www.cpax.org.uk
email: rjh at above domain (but drop the www, obviously)
Apr 21 '06 #2
Thank Richard very much!!

And your explaination is very detailed and clear. According to it, I think
I have understand the different between the two declarations
and I believe I can use them better from now.

Thanks again!!
"Richard Heathfield" <in*****@invalid.invalid> ????
news:LK******************************@bt.com...
robin liu said:
What's the difference between these two declarations ?

1) typedef void (*pf)(void);
2) typedef void f(void);

the first declaration is define a function pointer,


No, it defines a synonym for an existing function pointer type.
what is the second ? define a function model?


No, it defines a synonym for an existing function type.
And can use the second declaration to define a function pointer as follow:
typedef void f(void);
f *pf;


Yes.
Whether the two declarations of pf1 are both pointer to a function?

1) typedef void (*pf)(void);
pf pf1;
2) typedef void f(void);
f *pf1;


Yes.
if yes, which is better? and I saw many codes used the second declaration, what is its' advantage or disadvantage?


The advantage of the second is that it does not hide a pointer
characteristic inside a typedef. The * reminds us that here be dragons,
which can be a useful hint. So I use the second form.

--
Richard Heathfield
"Usenet is a strange place" - dmr 29/7/1999
http://www.cpax.org.uk
email: rjh at above domain (but drop the www, obviously)

Apr 21 '06 #3
After review my post news, I found that I make a big mistake.

Thanks to richard, you are right. The first declaration I said defines a
synonym for an existing function
pointer type, and the second defines a synonym for an existing function
type.

Thanks and apologize for my mistake once again !!


"Richard Heathfield" <in*****@invalid.invalid> ????
news:LK******************************@bt.com...
robin liu said:
What's the difference between these two declarations ?

1) typedef void (*pf)(void);
2) typedef void f(void);

the first declaration is define a function pointer,


No, it defines a synonym for an existing function pointer type.
what is the second ? define a function model?


No, it defines a synonym for an existing function type.
And can use the second declaration to define a function pointer as follow:
typedef void f(void);
f *pf;


Yes.
Whether the two declarations of pf1 are both pointer to a function?

1) typedef void (*pf)(void);
pf pf1;
2) typedef void f(void);
f *pf1;


Yes.
if yes, which is better? and I saw many codes used the second declaration, what is its' advantage or disadvantage?


The advantage of the second is that it does not hide a pointer
characteristic inside a typedef. The * reminds us that here be dragons,
which can be a useful hint. So I use the second form.

--
Richard Heathfield
"Usenet is a strange place" - dmr 29/7/1999
http://www.cpax.org.uk
email: rjh at above domain (but drop the www, obviously)

Apr 21 '06 #4

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

9 posts views Thread by David Hill | last post: by
8 posts views Thread by Bryan Parkoff | last post: by
11 posts views Thread by Rajesh | last post: by
23 posts views Thread by bluejack | last post: by
9 posts views Thread by key9 | last post: by
4 posts views Thread by Immortal_Nephi@hotmail.com | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.