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