首页 > 其他 > 详细

void * 指针算术运算【-Wpointer-arith】

时间:2014-03-11 13:16:32      阅读:1000      评论:0      收藏:0      [点我收藏+]

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 __cplusplus
extern "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.c
point.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.c
ok
  
gcc -Wpointer-arith point.c
point.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

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!