Andes Workshop

It is currently Mon Jul 22, 2019 3:15 pm

All times are UTC + 8 hours [ DST ]




Post new topic Reply to topic  [ 1 post ] 
Author Message
 Post subject: global 變數被最佳化
PostPosted: Fri Feb 10, 2012 4:22 pm 
Offline
User avatar

Joined: Fri Mar 04, 2011 9:36 pm
Posts: 500
下面這個code在最佳化之後,程式編譯出來的結果不如預期。

有一個global變數variTest,在interrupt來時會改變。
程式碼:
Attachment:
p1.gif
p1.gif [ 18.93 KiB | Viewed 3802 times ]


其中我標起來的那一行,
只要一開始variTest的bit 3為0就會進入無窮迴圈。

解決方法:
將變數variTest前面加上volatile,就可以如預期中會抓取variTest的值做判斷。
如下:
Attachment:
p2.gif
p2.gif [ 18.96 KiB | Viewed 3801 times ]


程式碼如下:
Attachment:
Hello.zip [45.94 KiB]
Downloaded 485 times


Top
 Profile Send private message E-mail  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 1 post ] 

All times are UTC + 8 hours [ DST ]


Who is online

Users browsing this forum: No registered users and 3 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
cron
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group