如何正确将char * const [256]转换为const char * const *

时间:2019-04-20 10:27:58

标签: c pointers casting const execv

我有这个结构:

typedef struct cmdLine {
char * const arguments[256];
} cmdLine;

我也有一个参数cmdLine *pCmdLine。我想使用execv,所以我写execv((pCmdLine->arguments[0]), pCmdLine->arguments);。第二个参数不适用于execv,我想问一下如何正确转换它。

我得到的警告是:将'char * const [256]''传递给'const char * const *'类型的参数会丢弃嵌套指针类型中的限定符。谢谢,我会撒谎以帮助其正确转换。

1 个答案:

答案 0 :(得分:0)

我看不到任何问题:

#include <stdint.h>
#include <stdlib.h>
#include <string.h>
#include <stdio.h>

#include <stdio.h>

struct
{
char * const arr[20];
}*str;

void foo(char  *const par[])
{
    volatile const char * const ptr = par[4]; 
    printf("%s\n", par[7]);
    printf("%s\n", ptr);
}


void foo1()
{
    foo(str -> arr);
}

https://godbolt.org/z/4Sv4a8

相关问题