Sim*_*imC 1 c linux gcc void-pointers pointer-arithmetic
我必须在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)
我能这样做吗?我应该忽略这个警告?
铸void *到char *.这样,你有一个大小为1的底层类型来进行指针运算.
(char*)data + (s*type)
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
2353 次 |
| 最近记录: |