藤田様の別スレッドに便乗なのですが、CS+のRL78のコード生成ツールが生成するuart通信機能のポインタ変数でvolatile修飾子の記述位置がおかしいものがあるように思います。具体的な変数名で言うと、gp_uart0_tx_addressとgp_uart0_rx_addressです。(CS+ for CC V5.00.00のコード生成機能で確認しました。)コード生成ツールが生成した変数宣言は以下の通りです。volatile uint8_t * gp_uart0_tx_address; /* uart0 send buffer address */volatile uint8_t * gp_uart0_rx_address; /* uart0 receive buffer address */ところが、以下の画面コピーの赤枠の箇所の通り、割り込みルーチン内で変更されるのはgp_uart0_tx_addressやgp_uart0_rx_addressの変数自身ですので以下の変数宣言が正しい気がします。uint8_t * volatile gp_uart0_tx_address; /* uart0 send buffer address */uint8_t * volatile gp_uart0_rx_address; /* uart0 receive buffer address */試しに型修飾子の作用の仕方がvolatileと同様なconst(型修飾子の作用自体(機能)としては対義語的になる)で試してみると、変数自身に作用したのは以下の画面コピーのように橙枠の方でしたので、volatileも変数自身に作用させる場合には同様である筈です。
> volatileは記述位置にはよりませんね。
いえ、拠りますが。
$ cat -n hoge.c 1 void hoge(void) 2 { 3 extern volatile int* hogehoge; 4 while (*hogehoge) { 5 ; 6 } 7 while (hogehoge) { 8 ; 9 } 10 } 11 12 void piyo(void) 13 { 14 extern int* volatile piyopiyo; 15 while (*piyopiyo) { 16 ; 17 } 18 while (piyopiyo) { 19 ; 20 } 21 } $ gcc -O2 -S hoge.c -o - .text hoge: movq .refptr.hogehoge(%rip), %rax movq (%rax), %rdx .L2: movl (%rdx), %eax testl %eax, %eax jne .L2 .L3: jmp .L3 .text piyo: movq .refptr.piyopiyo(%rip), %rax .L7: movq (%rax), %rdx movl (%rdx), %edx testl %edx, %edx jne .L7 .L9: movq (%rax), %rdx testq %rdx, %rdx jne .L9 ret $
分けた方が良かったかな。
$ cat -n piyo.c 1 extern volatile int* hogehoge; 2 3 void hoge(void) 4 { 5 while (*hogehoge) { 6 ; 7 } 8 } 9 10 void hogera(void) 11 { 12 while (hogehoge) { 13 ; 14 } 15 } 16 17 extern int* volatile piyopiyo; 18 19 void piyo(void) 20 { 21 while (*piyopiyo) { 22 ; 23 } 24 } 25 26 void piyora(void) 27 { 28 while (piyopiyo) { 29 ; 30 } 31 } $ gcc -O2 piyo.c -S -o - .text hoge: movq .refptr.hogehoge(%rip), %rax movq (%rax), %rdx .L2: movl (%rdx), %eax testl %eax, %eax jne .L2 ret .text hogera: movq .refptr.hogehoge(%rip), %rax movq (%rax), %rax .L6: testq %rax, %rax jne .L6 ret .text piyo: movq .refptr.piyopiyo(%rip), %rdx .L9: movq (%rdx), %rax movl (%rax), %eax testl %eax, %eax jne .L9 ret .text piyora: movq .refptr.piyopiyo(%rip), %rdx .L12: movq (%rdx), %rax testq %rax, %rax jne .L12 ret $
でも、わわいさん、RL78やRXの話にいつもいつもSHの話を持ち出されてますよね?(しかも、頻繁に他の人にRL78やRXでは話が違うと誤りを指摘されていて。)(さらに、誤りを指摘されても、意固地なまでに反論されることは有っても、素直に間違いを詫びる返事をされたことが無いという。)さすがに、あなたがそれを言いますか?という思いです、、、
わわいさんwrote: said:わわいです いや、元質問のトピックにわざわざGCCもってこられましても。。