warning: format ‘%p’ expects argument of type ‘void *’, but argument 3 has type ‘char **’

前端 未结 3 1144
孤街浪徒
孤街浪徒 2021-01-18 04:59

I\'m trying to print out the value of argv at this point in my code, but when I try to compile it, I get warning: format ‘%p’ expects argument of type ‘vo

3条回答
  •  栀梦
    栀梦 (楼主)
    2021-01-18 05:25

    Well, not any pointer (type).

    According to C11, chapter §7.21.6.1, for the %p conversion specifier,

    p

    The argument shall be a pointer to void. The value of the pointer is converted to a sequence of printing characters, in an implementation-defined manner.

    So, the argument must be of type void * (or, a char*, given they have the same alignment requirements). Any other type of pointers, must be converted through an explicit cast, as there is no default argument promotion for pointers.

    Something like

    printf("%s%p", "argv = ", (void *)argv);
    

    should do.

提交回复
热议问题