想试验下strcpy_s
网上搜索说要这么写
#define __STDC_WANT_LIB_EXT1__ 1
#include <string.h>
#include <stdio.h>
#include <stdlib.h>
int main(void)
{
char *src = "Take the test.";// src[0] = 'M' ; // this would be undefined behavior
char dst[strlen(src) + 1]; // +1 to accomodate for the null terminator strcpy(dst, src);
dst[0] = 'M'; // OK printf("src = %s\ndst = %s\n", src, dst);
#ifdef __STDC_LIB_EXT1__
set_constraint_handler_s(ignore_handler_s);
int r = strcpy_s(dst, sizeof dst, src);
printf("dst = \"%s\", r = %d\n", dst, r);
r = strcpy_s(dst, sizeof dst, "Take even more tests.");
printf("dst = \"%s\", r = %d\n", dst, r);
#endif
}
编译的时候也添加了 -std=c11
gcc版本是gcc version 9.4.0 (Ubuntu 9.4.0-1ubuntu1~20.04.2) 应该也支持c11
但是编译完执行,什么都没有打印出来
--
FROM 218.66.91.*