XCode调试错误
1. 警告Conversion specifies type'int' but the argument has type'size_t'
代碼:
#import<Foundation/Foundation.h> int main(int argc,const char * argv[]){const char *words[4]={"mother","father","sister","ms"}; int wordCount=4;int i;for(i=0;i<wordCount;i++){NSLog(@"%s is %d characters long",words[i],strlen(words[i])); }return (0); }解決:
把%d改為%zu就沒有警告了
分析:
%d是輸出數字整數,警告里面的size_t是unsigned int
size_t 和int的區別是
size_t是一些C/C++標準在stddef.h中定義的。這個類型足以用來表示對象的大小。
size_t的真實類型與操作系統有關,在32位架構中被普遍定義為:
typedef unsigned int size_t;
而在63位架構中被定義為:
typedef unsigned long size_t;
size_t在32位架構上是4字節,在64位架構上是8字節,在不同架構上進行編譯時需要注意這個問題
int在不同架構下都是4字節
int是帶符號書,size_t是無符號數
轉載于:https://www.cnblogs.com/cc-Cheng/p/3312895.html
總結
- 上一篇: Linux常用指令总结二~~
- 下一篇: swift 点击响应视图之外的地方