指针(地址变量)以 %#x 方式输出的东西有什么含义吗?
c4droid吧
全部回复
仅看楼主
level 6
csgffc 楼主
注:在安卓手机termux(clang)上编译会出现三个“警告(warning)”……[汗]
#include <stdio.h>
void point (char *ss) {
char *px = ss;
printf("%#x\n", px);
++px;
printf("%#x\n", px);
}
int main (void) {
char s[99];
point(&s);
return 0;
}
2017年12月17日 05点12分 1
level 6
csgffc 楼主
$ cat test_p.c
#include <stdio.h>
void point (char *ss) {
char *px = ss;
printf("%#x\n", px);
++px;
printf("%#x\n", px);
}
int main (void) {
char s[99];
point(&s);
return 0;
}
$ clang test_p.c
test_p.c:5:21: warning: format specifies type 'unsigned int' but the argument has type
'char *' [-Wformat]
printf("%#x\n", px);
~~~ ^~
%s
test_p.c:7:21: warning: format specifies type 'unsigned int' but the argument has type
'char *' [-Wformat]
printf("%#x\n", px);
~~~ ^~
%s
test_p.c:12:11: warning: incompatible pointer types passing 'char (*)[99]' to parameter of
type 'char *' [-Wincompatible-pointer-types]
point(&s);
^~
test_p.c:3:19: note: passing argument to parameter 'ss' here
void point (char *ss) {
^
3 warnings generated.
$ ./a.out
0xca7d9a48
0xca7d9a49
$
2017年12月17日 05点12分 2
level 6
csgffc 楼主
clang的警告
贴吧的文字效果看来不行
2017年12月17日 05点12分 3
level 9
它会强行把指针地址值以16进制数显示,指针应该用%p显示。
2017年12月17日 13点12分 4
1