source: CIVL/examples/languageFeatures/functionPointer.cvl@ 1450740

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

minor corrections of examples.

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

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