gpt4 book ai didi

c - 警告 : argument is incompatible with prototype (C) | address of char [] V. S.char**

转载 作者:行者123 更新时间:2023-12-02 07:07:34 25 4
gpt4 key购买 nike

我有一个字符数组。我获取它的地址并将其传递给接受双字符指针的函数:

char result[1024+1];
memset(result, 0, sizeof(result));
executeGetQuery(query, &(result));

函数定义:int executeGetQuery(char * query, char ** queryResultData)

我得到这个编译时错误

warning: argument #2 is incompatible with prototype:
prototype: pointer to pointer to char : line 1531
argument : pointer to array[1025] of char

我以前总是在 C 中将数组作为指针传递。为什么会出现此错误?是我的编译器造成的吗?

编辑:修复方法是什么?
EDIT2: 我希望函数向结果数组写入一些内容,这就是我传递 char** 而不是 char* 的原因。那么还有什么方法可以让函数写入我传入的参数?

最佳答案

char** 表示函数将写入给定的内存位置,类似于:

int executeGetQuery(char * query, char ** queryResultData) {
char* buffer = malloc( ... );
/* get the query results into buffer */
*queryResultData = buffer;
...
}

你不能用数组来做,它的地址是不可写的。

关于c - 警告 : argument is incompatible with prototype (C) | address of char [] V. S.char**,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9301621/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com