xref: /llvm-project/lldb/test/API/lang/c/blocks/main.c (revision 4f14c17df70916913d71914343dd4f6c709e218d)
1 #include <stdio.h>
2 
3 struct CG {int x; int y;};
4 
5 int g(int (^callback)(struct CG)) {
6    struct CG cg = {.x=1,.y=2};
7 
8    int z = callback(cg); // Set breakpoint 2 here.
9 
10    return z;
11 }
12 
h(struct CG cg)13 int h(struct CG cg){return 42;}
14 
main()15 int main()
16 {
17     int c = 1;
18 
19     int (^add)(int, int) = ^int(int a, int b)
20     {
21         return a + b + c; // Set breakpoint 0 here.
22     };
23 
24     int (^neg)(int) = ^int(int a)
25     {
26         return -a;
27     };
28 
29     printf("%d\n", add(3, 4));
30     printf("%d\n", neg(-5)); // Set breakpoint 1 here.
31 
32     int (^add_struct)(struct CG) = ^int(struct CG cg)
33     {
34         return cg.x + cg.y;
35     };
36 
37     g(add_struct);
38 
39     return 0;
40 }
41