source: CIVL/examples/languageFeatures/functionPointer.cvl@ 8f51b55

1.23 2.0 main test-branch
Last change on this file since 8f51b55 was f1be440, checked in by Manchun Zheng <zmanchun@…>, 12 years ago

implemented support for function pointers; still need to modify the POR accordingly.

git-svn-id: svn://vsl.cis.udel.edu/civl/trunk@721 fb995dde-84ed-4084-dfe6-e5aef3e2452c

  • Property mode set to 100644
File size: 654 bytes
Line 
1#include <civlc.h>
2#include <stdio.h>
3
4int min(int a, int b) {
5 if (a < b)
6 return a;
7 else
8 return b;
9}
10
11int minDouble(int (*f)(int, int), int a, int b) {
12 int result;
13
14 result = f(a, b);
15 return result * 2;
16}
17
18$proc proc_create(void (*f)(int), int x){
19 $proc p = $spawn f(x);
20
21 return p;
22}
23
24void foo(int id) {
25 printf("I'm spawned with id %d.\n", id);
26}
27
28void main(){
29 int k = minDouble(min, 5, 8);
30 $proc procs[4];
31
32 printf("The result is %d.\n", k);
33
34 for(int i = 0; i < 4; i++){
35 procs[i] = proc_create(foo, i);
36 }
37
38 for(int i = 0; i < 4; i++){
39 $wait(procs[i]);
40 printf("Process %d terminates.\n", i);
41 }
42}
Note: See TracBrowser for help on using the repository browser.