By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
434,786 Members | 1,131 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 434,786 IT Pros & Developers. It's quick & easy.

about typedef the name of a function

P: 30
Expand|Select|Wrap|Line Numbers
  1. typedef void (f)(void);//it is not (*f)
  2.  
  3. void funptr(f parafun)
  4. {
  5.      parafun();
  6. }
  7.  
  8.  
  9.  
  10. void fun()
  11. {
  12.    printf("test\r\n");
  13. }
  14.  
  15.  
  16.  
How to understand that:
Expand|Select|Wrap|Line Numbers
  1. int main()
  2. {
  3.    funptr(fun);//1.ok
  4.    f parafun=fun;//2.error
  5.    return 0;
  6. }
  7.  
Mar 23 '11 #1
Share this Question
Share on Google+
2 Replies


Expert 100+
P: 2,400
Change the typedef from "(f)" to "(*f)" and I think all of the errors will go away. That is, declare type f as a function pointer.

Why do you insist on not using function pointers?
Mar 23 '11 #2

P: 30
I really want to know what is "typedef void (f)(void)"but not "*pf"
Mar 25 '11 #3

Post your reply

Sign in to post your reply or Sign up for a free account.