我有一个函数可以像这样进行重新分配:
void str_replace(char** str, const char* a, const char* b)
{
*str = realloc(*str, 100);
}
我在 main 中调用该函数:
char test[] = "some test string";
str_replace(&test, "test", "tested");
但是 gcc 会发出警告:
../main/app_main.c: In function 'app_main':
../main/app_main.c:567:17: warning: passing argument 1 of 'str_replace' from incompatible pointer type [-Wincompatible-pointer-types]
str_replace(&test, "test", "tested");
^~~~~
../main/app_main.c:186:30: note: expected 'char **' but argument is of type 'char (*)[17]'
esp_err_t str_replace(char **str_to_replace, const char *old, const char *new)
两个问题:
- 如何将 char (*)[n] 类型的对象转换为 char**?
- 我正在尝试重新分配堆栈分配的对象。这甚至允许吗?