• slider image 442
  • slider image 483
  • slider image 484
  • slider image 485
  • slider image 486
  • slider image 487
:::


Browsing this Thread:   1 Anonymous Users






Re: 在 ccsc 中const 和 static宣告的變數有何不同?
#3
資深會員
資深會員


查看用戶資訊
參照:

test452 寫道:
在 ccsc 中const 和 static宣告的變數有何不同?


把下面這個範例 compile 一下,再看看編出來的
LST 檔 ( ASM 組語) 和 SYM 檔 (符號變數佔用的記憶體)
就知道啦

跑跑程式,仔細的,仔細的做做實驗吧

#include <18F452.H>
#use delay(clock=20000000)
#use RS232(baud=9600, xmit=PIN_C6, rcv=PIN_C7)

const int8 k[3] = {357};  // 常數,不佔用 RAM
int8       z;                 // global variable, 總體變數

int8 fun_1(int8 x)
{
   
int8        c;             // 會與他人共用 RAM 的局部變數         
   
static int8 s 7;         // 不與他人共用 RAM 的局部變數
   
   
s  x;  

   
printf(" s = %u"s);      // 試試看,s 會印出什麼數字?   

   
c  k[2];
   return 
c;
}

int8 fun_2(int8 x)
{
   
int8        c;
   static 
int8 s;             // 不與他人共用 RAM 的局部變數,初始化為 0
   
   
s  x;  

   
printf(" s = %u"s);      // 試試看,s 會印出什麼數字?   

   
c  k[2];
   return 
c;
}

void main()
{
   
int8        xy;    // local variable, 局部變數
   
const int8  kc 2;  // 常數

   
x     2;
   
y     k[1] + x;
   
z     kc y;  

// kc    = z - y;    // 能這樣用嗎?

   
y     fun_1(x); // 試試看,s 會印出什麼數字?
   
z     fun_1(y); // 試試看,s 會印出什麼數字?

   
y     fun_2(x); // 試試看,s 會印出什麼數字?
   
z     fun_2(y); // 試試看,s 會印出什麼數字?
}


SYM 檔
005     z
006     fun_1
.s
007     fun_2
.s
008     main.x
009     main.y
00A     fun_2
.// 和 fun_1.x 共用 RAM
00A     fun_1.x
00B     fun_2
.// 和 fun_1.c 共用 RAM
00B     fun_1.c


LST 檔
.................... void main()
.................... {
010E:  CLRF   TBLPTRU
... 略 ...
011E:  MOVLW  81
0120
:  MOVWF  SPBRG
0122
:  MOVLW  26
0124
:  MOVWF  TXSTA
0126
:  MOVLW  90
0128:  MOVWF  RCSTA
012A
:  MOVLW  07
012C
:  MOVWF  s // fun_1.s 初始化為 7
012E:  CLRF   s // fun_2.s 初始化為 0
... 略 ... 自己去看吧


發表於: 2004/10/26 22:39
Twitter Facebook Google Plus Linkedin Del.icio.us Digg Reddit Mr. Wong 頂部


Re: 在 ccsc 中const 和 static宣告的變數有何不同?
#2
資深會員
資深會員


查看用戶資訊
const宣告好像是表固定值,即不會變的數值.
static就不知道勒..

發表於: 2004/10/26 20:29
Twitter Facebook Google Plus Linkedin Del.icio.us Digg Reddit Mr. Wong 頂部


在 ccsc 中const 和 static宣告的變數有何不同?
#1
新會員
新會員


查看用戶資訊
在 ccsc 中const 和 static宣告的變數有何不同?

發表於: 2004/10/26 16:19
Twitter Facebook Google Plus Linkedin Del.icio.us Digg Reddit Mr. Wong 頂部







You can view topic.
不可以 發起新主題
You cannot reply to posts.
You cannot edit your posts.
You cannot delete your posts.
You cannot add new polls.
You cannot vote in polls.
You cannot attach files to posts.
You cannot post without approval.
You cannot use topic type.
You cannot use HTML syntax.
You cannot use signature.
You cannot create PDF files.
You cannot get print page.

[進階搜尋]


:::

Microchip連結

https://www.facebook.com/microchiptechnologytaiwan/
http://www.microchip.com.tw/modules/tad_uploader/index.php?of_cat_sn=13
https://mu.microchip.com/page/tmu
http://elearning.microchip.com.tw/modules/tad_link/index.php?cate_sn=1
https://page.microchip.com/APAC-PrefCenters-TW.html
http://www.microchip.com/
http://www.microchip.com/treelink
http://www.microchipdirect.com/
http://www.microchip.com.cn/newcommunity/index.php?m=Video&a=index&id=103
http://www.microchip.com.tw/modules/tad_uploader/index.php?of_cat_sn=2
http://www.microchip.com.tw/Data_CD/eLearning/index.html
http://www.microchip.com.tw/RTC/RTC_DVD/
https://www.microchip.com/development-tools/
https://www.youtube.com/user/MicrochipTechnology
[ more... ]

教育訓練中心

!開發工具購買
辦法說明 [業界客戶] [教育單位]
----------------------------------
!校園樣品申請
辦法說明 [教師資格] [學生資格]
----------------------------------