Andes Workshop http://forum.andestech.com/ |
|
global 變數被最佳化 http://forum.andestech.com/viewtopic.php?f=16&t=528 |
Page 1 of 1 |
Author: | cindy [ Fri Feb 10, 2012 4:22 pm ] |
Post subject: | global 變數被最佳化 |
下面這個code在最佳化之後,程式編譯出來的結果不如預期。 有一個global變數variTest,在interrupt來時會改變。 程式碼: Attachment: p1.gif [ 18.93 KiB | Viewed 7348 times ] 其中我標起來的那一行, 只要一開始variTest的bit 3為0就會進入無窮迴圈。 解決方法: 將變數variTest前面加上volatile,就可以如預期中會抓取variTest的值做判斷。 如下: Attachment: p2.gif [ 18.96 KiB | Viewed 7347 times ] 程式碼如下: Attachment:
|
Page 1 of 1 | All times are UTC + 8 hours [ DST ] |
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group http://www.phpbb.com/ |