2007年3月5日 星期一

The Function Pointer Tutorials

1.
http://www.newty.de/fpt/fpt.html#chapter2

2.
http://publications.gbdirect.co.uk/c_book/chapter8/typedef.html

3.
Hide Function Pointer Declarations With a typedef

Can you tell what the following declaration means?

void (*p[10]) (void (*)() );

Only few programmers can tell that p is an "array of 10 pointers to a function returning void and taking a pointer to another function that returns void and takes no arguments." The cumbersome syntax is nearly indecipherable. However, you can simplify it considerably by using typedef declarations. First, declare a typedef for "pointer to a function returning void and taking no arguments" as follows:

typedef void (*pfv)();

Next, declare another typedef for "pointer to a function returning void and taking a pfv" based on the typedef we previously declared:

typedef void (*pf_taking_pfv) (pfv);

Now that we have created the pf_taking_pfv typedef as a synonym for the unwieldy "pointer to a function returning void and taking a pfv", declaring an array of 10 such pointers is a breeze:

pf_taking_pfv p[10];

[ 轉錄 ]
http://www.devx.com/tips/Tip/13829

沒有留言: