I found this example at https://en.cppreference.com/w/c/string/byte/strcpy
#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
}
Using nvcc compiler, I get an error on the line char dst[strlen(src) + 1];
"expression must have a constant value."
Using Visual C++, I get that error and another error, "C++ a value of type cannot be used to initialize an entity of type," on the line char *src = "Take the test.";
If I compile and run it on the site, it's fine.