【发布时间】:2016-09-25 22:59:19
【问题描述】:
我必须在 Linux 上用 C 语言编写一个函数来读取或写入通用数据。
我可以读取(或写入)大数据,所以我花了一段时间使用我读取的字节数。 例如,在下一次调用 i 时,读取原始指针 + 我读取的字节数。但我不知道类型,所以我使用了 void * 但 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);
我可以这样做吗?我应该忽略这些警告吗?
【问题讨论】:
-
char*可能是您想要进行算术运算的指针类型。 -
OT:那些
long ints 也应该是size_ts。 -
OT^2:按照约定返回错误
-1。
标签: c linux gcc void-pointers pointer-arithmetic