2013-11-21 41 views
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() 感謝您的幫助數組定義和起始上述

回答

0

您將初始化init正文中的筷子陣列。

#define NUM_PHIL 4 

byte chopstick[4]; /* NUM_PHIL */ 

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

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

    run phil (0); 
    /* ... */ 
}