代码之家  ›  专栏  ›  技术社区  ›  J. Doe

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

  •  0
  • J. Doe  · 技术社区  · 7 年前

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

    我也有一个论点 cmdLine *pCmdLine . 我想用 execv 所以我写 execv((pCmdLine->arguments[0]), pCmdLine->arguments); 执行 我想问一下如何正确地转换它。

    我得到的警告是: 将“char*const[256]”传递给“const char*const*”类型的参数将丢弃嵌套指针类型中的限定符 . 我会骗你帮我把它转换好的,谢谢。

    0 回复  |  直到 7 年前
        1
  •  0
  •   0___________    7 年前

    我看不出任何问题:

    #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