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

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

#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



  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值