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

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

fixed function pointer example.

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

  • Property mode set to 100644
File size: 682 bytes
RevLine 
[f1be440]1#include <civlc.h>
2#include <stdio.h>
[c358a25]3$proc procs[4];
[f1be440]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) {
[d46c68d]26 _Bool checkPid = equalsTo(procs[id], $self);
27
[f1be440]28 printf("I'm spawned with id %d.\n", id);
[d46c68d]29 $assert(checkPid);
[f1be440]30}
31
32void main(){
33 int k = minDouble(min, 5, 8);
[c358a25]34
[f1be440]35 for(int i = 0; i < 4; i++){
36 procs[i] = proc_create(foo, i);
37 }
38
39 for(int i = 0; i < 4; i++){
40 $wait(procs[i]);
41 printf("Process %d terminates.\n", i);
42 }
43}
Note: See TracBrowser for help on using the repository browser.