【发布时间】:2017-06-05 17:00:12
【问题描述】:
我正在编写一个程序,并获得了一个存储为 unsigned int 的内存位置,并且映射的长度为 unsigned int,我想取消映射。
我的以下方法会产生警告:
warning: passing argument 1 of ‘munmap’ makes pointer from integer without a cast [enabled by default]
/usr/include/i386-linux-gnu/sys/mman.h:77:12: note: expected ‘void *’ but argument is of type ‘unsigned int’
这引起了我的警告:
//startAddr and addrRange are stored as an unsigned int,
void unmap(mapping_t *maps, const int *curSize){
int i = 0;
for (; i < *curSize; i++){
munmap(maps[i].startAddr, maps[i].addrRange);
}
}
当我点击 munmap 时,我的程序也会崩溃,但我假设它必须以某种方式处理警告
根据要求定义 struct mapping_t:
typedef struct mapping{
unsigned int startAddr;
unsigned int endAddr;
unsigned int addrRange;
} mapping_t;
【问题讨论】:
-
发布
mapping_t的定义。我当然希望你不会真正将指针值填充到unsigned int中。 -
编译器肯定认为他是
标签: c memory-management mmap