映射函数mmap 的定义是void* 型
void* mmap(void* start,size_t length,int prot,int flags,int fd,off_t offset);
但是大多数调用时候,要求其是有返回值的。例如定义一个unsigned char *buf
再将buf 作为mmap 函数的返回值。
若直接 使用buf = mmap(void* start,size_t length,int prot,int flags,int fd,off_t offset);则会报错
然后可以讲空指针性强转:
unsigned char *buf = (unsigned char*)mmap(0,creq.size,PROT_READ | PROT_WRITE, MAP_SHARED,newLease,mreq.offset);
在mmap函数前也加上(unsigned char*)则可编译通过转载请标明出处:(void*)mmap()
文章来源: (void*)mmap()