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