作者: hover99 时间: 2016-4-5 10:37
for (int ii = 0; ii < 16; ii+=)
fork
begin
automatic int jj;
jj = ii;
send(jj);
end
join_none
end作者: 打回原形 时间: 2016-4-5 14:17 回复 4#hover99
我知道声明一个中间自动变量可以解决,但是automatic的program里面的变量默认是automatic,那么for循环里的 i 也是automatic, 按道理没必要中间再复制一份吧。一般加中间自动变量用于解决static的program,还望大神解释下我截的两张图中同样在automatic的program
中,automatic的 i 和 static的 i 为啥得到相同的结果,两者的变量内存分配是怎么回事,谢谢作者: AnswerLJ 时间: 2016-4-5 15:53
program automatic test ;
int i; // not within a procedural block - static
task t ( int a ); // arguments and variables in t are automatic
... // unless explicitly declared static
endtask
endprogram
复制代码
IEEE 1800-2012有解释作者: hover99 时间: 2016-4-5 17:04 回复 5#打回原形
不好意思,说错了。应该这样改:task automatic send(int j);
fork
begin
$display();
#1;
end
join_none
endtask
initial begin
for (int ii = 0; ii < 16; ii ++) begin
send(ii);
end
end
仿真器遇到fork join_none语句,会直接跳到join_none之后继续执行直到遇到阻塞语句。在你的例子里,仿真器会先执行16次for循环,然后才会执行16个fork,所以在fork里面看到的ii会是16.作者: 打回原形 时间: 2016-4-5 19:33 回复 7#hover99