Why does this allow promotion from (char *) to (const char *)?

后端 未结 4 400
野性不改
野性不改 2021-01-13 18:53

Given that scanf has (const char *) in the documentation from Microsoft and the answer to this question what the heck is going when I do the same for (char **) promotion to

4条回答
  •  夕颜
    夕颜 (楼主)
    2021-01-13 19:34

    char** -> const char ** is dangerous, since you might end up accidentally modifying the underlying const object.

    The correct way to write what you want is:

    void processargs(const char * const *p)
    { 
    }
    

提交回复
热议问题