在 Macos下使用string.h中的 strcat 结果实际调用的是 _string.h 中的strcat声明。
#include <string.h>
#include <stdio.h>
void strings() {
char str[] = "abcd";
char str1[] = "efg";
strcat(str, str1);
printf("拼接后的 str 值为:%s\n", str);
}
在Macos 下这段代码不报错什么也不打印,使用 ide 点击 strcat 定位到:/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.12.sdk/usr/include/secure/_string.h,头文件中的 strcat 声明中。在 _string.h 中声明如下
#if __has_builtin(__builtin___strcat_chk) || defined(__GNUC__)
#undef strcat
#define strcat(dest, src) \
__builtin___strcat_chk (dest, src, __darwin_obsz (dest))
#endif
你
str
分配的内存空间不足呀,你试试大点的,就可以了。