作者descent (「雄辯是銀,沉默是金」)
看板Programming
標題Re: [請益] C 變數型態 可攜
時間Tue Feb 5 11:17:31 2013
http://www.cnblogs.com/zyl910/archive/2012/08/02/printmacro.html
http://www.cnblogs.com/zyl910/archive/2012/08/08/c99int.html
這兩篇可以參考如何處理沒有支援 stdint.h、inttypes.h
※ 引述《dryman (dryman)》之銘言:
: http://www.idryman.org/blog/2012/11/21/integer-promotion/
#include <stdio.h>
int main(void)
{
unsigned char a = 0xff;
char b = 0xff;
int c = a==b; // true, or false?
printf("C: %d\n",c);
}
這篇提到的程式碼做了一個假設:
char b 是 signed, 不過 char 是 signed 或是 unsigned 是由
c compiler 決定的。
你的範例我在 gcc, openwatcom c/c++ 結果不同。
參考一下:
http://descent-incoming.blogspot.tw/2013/02/c-char-signed-unsigned.html
--
※ 發信站: 批踢踢實業坊(ptt.cc)
◆ From: 59.125.239.46
※ 編輯: descent 來自: 59.125.239.46 (02/05 11:27)
→ dryman:是descent大大(拜) 68.181.4.88 02/06 10:00
推 dryman:不過,integer promotion在C99中有規範 68.181.4.88 02/06 10:07
→ dryman:並不是implementation defined 68.181.4.88 02/06 10:08
→ dryman:我還要再查查C89有沒有定義,因為之前我只 68.181.4.88 02/06 10:08
→ dryman:有讀C99.... 68.181.4.88 02/06 10:08
推 dryman:C89也有integer promotion 68.181.4.88 02/06 10:11
→ dryman:C89是3.2.1.1,C99是6.3.1.1 68.181.4.88 02/06 10:13
→ descent:真強大, 直接讀 c99 spec, 這資料比任何書 59.125.239.51 02/06 10:52
→ descent:可靠多了 59.125.239.51 02/06 10:52
推 dryman:C99 spec跟C99 rationale混著讀,其實還蠻 68.181.4.88 02/06 11:00
→ dryman:快的。而且還有範例說明 68.181.4.88 02/06 11:00