Why I get; initializing 'char *' with an expression of type 'const char *' discards qualifiers?

后端 未结 6 1145
陌清茗
陌清茗 2021-01-05 05:37

I can\'t figure out why I get this warning from clang by myself:

function_prototype_const_modifier.c:13:8: warning: initializing \'char *\' with         


        
6条回答
  •  走了就别回头了
    2021-01-05 06:14

    Because type of L.H.S is char * and type of R.H.S is const char *.

    The reason is exactly as what error says:

    function_prototype_const_modifier.c:13:8: warning: initializing 'char *' with an expression of type 'const char *' discards qualifiers

    The statement allows you to discard the const qualifier and it allows to modify the pointed string through ptr1 and ptr2 and hence the compiler complains.

提交回复
热议问题