我试图将参数传递给函数,并指示const接收函数应该考虑该参数.
我的理解是,下面的代码示例显示了确保test可以使用argv变量调用该函数的唯一方法,该变量未声明为const.
void test(const char * const *arr);
int main(int argc, char *argv[], char *env[])
{
test(argv);
}
void test(const char * const *arr)
{
}
Run Code Online (Sandbox Code Playgroud)
但是,gcc给了我一个警告,如下所示:
E:\Projects\test>gcc -o test test.c
test.c: In function 'main':
test.c:5:2: warning: passing argument 1 of 'test' from incompatible pointer type
[enabled by default]
test.c:1:6: note: expected 'const char * const*' but argument is of type 'char **'
Run Code Online (Sandbox Code Playgroud)
这让我相信我在这里所做的事情是错误的.有没有更好的方法将参数传递给函数,并指出它应该被const接收函数考虑?
| 归档时间: |
|
| 查看次数: |
6204 次 |
| 最近记录: |