小编Sim*_*imC的帖子

GCC警告:类型为void*的指针算术

我必须在Linux上的C中编写一个函数来读取或写入通用数据.

我可以读取(或写入)大数据,所以我用了多少字节读了一会儿.例如,在下一次调用i时,读入原始指针+我读取的字节数.但是我不知道这种类型,所以我使用了一个空格*但是gcc说:

membox.c: In function ‘myRW’:
membox.c:301:22: warning: pointer of type ‘void *’ used in arithmetic [-Wpointer-arith]
w = read(fd, data + (s*type) , len - s);
                  ^
membox.c:308:23: warning: pointer of type ‘void *’ used in arithmetic [-Wpointer-arith]
w = write(fd, data + (s*type) , len - s);
Run Code Online (Sandbox Code Playgroud)

我能这样做吗?我应该忽略这个警告?

c linux gcc void-pointers pointer-arithmetic

1
推荐指数
1
解决办法
2353
查看次数

标签 统计

c ×1

gcc ×1

linux ×1

pointer-arithmetic ×1

void-pointers ×1