I recently read the source code of Asterisk. I decided to record some of my work in learning Asterisk and share it with you. It is also convenient for me to refer to it later ......
What surprised me today is the use of the struct initialization (or assignment) in Asterisk.
For example, the struct is defined as follows:
Typedef struct ST {
Int;
Int B;
PFun fun;
} ST;
The general Initialization is as follows:
ST t2;
T2.a = 4;
T2. B = 5;
T2.fun = test2;
What I see in the source code is as follows:
ST t1 = {. a = 1,. B = 2,. fun = test1 };
Feeling strong ......
Here is the complete code I wrote following the example:
1 # include <stdio. h>
2
3 typedef void (* pFun) (int );
4
5 typedef struct ST {
6 int;
7 int B;
8 pFun fun;
9} ST;
10
11 void test1 (int)
12 {
13 printf ("test1: % d \ r \ n", );
14}
15
16 void test2 (int)
17 {
18 printf ("test2: % d \ r \ n", );
19}
20
21 int main ()
22 {
23 ST t1 = {
24. a = 1,
25. B = 2,
26. fun = test1
27 };
28
29 printf ("% d \ t % d \ n", t1.a, t1. B );
30 t1.fun (3 );
31
32 ST t2;
33 t2.a = 4;
34 t2. B = 5;
35 t2.fun = test2;
36
37 printf ("% d \ t % d \ n", t2.a, t2. B );
38 t2.fun (6 );
39
40 return 0;
41}
Save the disk test20120608.c and perform the following operations:
Make test20120608 &./test20120608
Test results:
From MikeZhang's blog