void * 指针算术运算【-Wpointer-arith】
|
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56 |
#ifdef __cplusplusextern
"C"{#endif #include <stdio.h>#include <string.h> int
main(int
argc,char* argv[]){ printf("argc(%d)\n",argc); int
n = 0; for(n=0;n<argc;++n) { printf("argv[%d]:%s\n",n,argv[n]); } void
*test = NULL; int
value_int[] = {12, 34, 56, 67, 27}; char
value_char[] = {‘H‘, ‘e‘, ‘l‘, ‘l‘, ‘o‘}; test = (void
*)value_char; printf("%c\n", *(value_char + 1)); printf("%c\n", *((char
*)(test + 1))); test = NULL; test = (void
*)value_int; printf("%d\n", *(value_int + 1)); //printf("%d\n", *((int *)(test + 1))); printf("%p\n", test + 1); printf("sizeof %d\n", sizeof(test)); return
0;} /*g++ -Wpointer-arith point.c / g++ point.cpoint.c: 在函数‘int main(int, char**)’中:point.c:67:35: 警告: ‘void *’型指针用在了算术表达式中 [-Wpointer-arith]point.c:73:34: 警告: ‘void *’型指针用在了算术表达式中 [-Wpointer-arith]point.c:75:31: 警告: ‘sizeof’不能用于 void 类型 [-Wpointer-arith] gcc point.cok gcc -Wpointer-arith point.cpoint.c: 在函数‘main’中:point.c:67:35: 警告: ‘void *’型指针用在了算术表达式中 [-Wpointer-arith]point.c:73:34: 警告: ‘void *’型指针用在了算术表达式中 [-Wpointer-arith]point.c:75:31: 警告: ‘sizeof’不能用于 void 类型 [-Wpointer-arith] */ #ifdef __cplusplus}#endif |
void * 指针算术运算【-Wpointer-arith】,布布扣,bubuko.com
void * 指针算术运算【-Wpointer-arith】
原文:http://www.cnblogs.com/freezlz/p/3589552.html