1
1 #define NUM_PHIL 4
2 
3 byte chopstick[4];
4 chopstick[0] = 1;
5 chopstick[1] = 1;
6 chopstick[2] = 1;
7 chopstick[3] = 1;
8 
9 proctype phil(int id) {
10    do 
11      ::printf("Philosopher %d is thinking\n",id);
12      /* ... */
13      printf("Philosopher %d is eating with forks %d and %d\n",id,id,(id+1)%4);
14      /* ... */
15    od
16    }
16a
17 init {
18    int i = 0; 
19    do 
20    :: i >= NUM_PHIL -> break
21    :: else -> run phil(i); 
22               i++ 
23    od 
24    }

上面的代码发送错误“语法错误在'筷子'附近看到'一个标识符'”我如何将数组定义和初始化为原型P()之外的全局变量感谢您的帮助

4

1 回答 1

0

您将在正文中初始化筷子数组init

#define NUM_PHIL 4

byte chopstick[4];    /* NUM_PHIL */

proctype phil (int n) { /* ... */ }

init {
  chopstick[0] = 1;
  /* ... */

  run phil (0);
  /* ... */
}
于 2013-11-23T00:29:16.657 回答