開發平台(Platform): (Ex: VC++, GCC, Linux, ...)
GCC
額外使用到的函數庫(Library Used): (Ex: OpenGL, ...)
N
問題(Question):
程式中有一段敘述大致上是這樣:
char Buf[1024];
int Inx;
for(Inx=0x000; Inx<sizeof(Buf); Inx=Inx+1)
{
...
}
compiler不太喜歡它,所以說了:
warning: comparison between signed and unsigned integer expressions
它說的signed integer應該是指Inx,所以我想sizeof()的回傳值是unsigned integer
型態,下面新手十戒有提到不同資料型態的兩個值不該被拿來比較、賦值,請問在這
狀況中,如果我想轉型成相同的型態:
for(Inx=0x000; Inx<(int)sizeof(Buf); Inx=Inx+1)
或
for(Inx=0x000; (unsigned int)Inx<sizeof(Buf); Inx=Inx+1)
哪個是比較好的選擇呢?或是還有其他更好的做法嗎?
餵入的資料(Input):
預期的正確結果(Expected Output):
錯誤結果(Wrong Output):
程式碼(Code):(請善用置底文網頁, 記得排版)
補充說明(Supplement):
沒有了。
--
※ 發信站: 批踢踢實業坊(ptt.cc)
◆ From: 203.67.181.135
→
01/21 19:17, , 1F
01/21 19:17, 1F
→
01/21 19:18, , 2F
01/21 19:18, 2F
推
01/21 19:18, , 3F
01/21 19:18, 3F
→
01/21 19:19, , 4F
01/21 19:19, 4F
推
01/21 19:20, , 5F
01/21 19:20, 5F
推
01/21 19:36, , 6F
01/21 19:36, 6F
→
01/21 19:37, , 7F
01/21 19:37, 7F
→
01/21 21:03, , 8F
01/21 21:03, 8F
→
01/21 21:03, , 9F
01/21 21:03, 9F
→
01/21 21:50, , 10F
01/21 21:50, 10F