警告:从不同大小的整数转换为指针[-Wint到指针转换]c编程
我不明白为什么会触发此警告 test.c:920:56:警告:从不同大小的整数转换为指针[-Wint转换为指针] ifmemcpyvoid*buffer\u post\u offset+位置,void*data\u block\n,bytes\u to\u write==NULL{ 这是一段代码警告:从不同大小的整数转换为指针[-Wint到指针转换]c编程,c,warnings,memcpy,C,Warnings,Memcpy,我不明白为什么会触发此警告 test.c:920:56:警告:从不同大小的整数转换为指针[-Wint转换为指针] ifmemcpyvoid*buffer\u post\u offset+位置,void*data\u block\n,bytes\u to\u write==NULL{ 这是一段代码 char *buffer_post_offset = NULL; // .... // Gets the data between offset and si
char *buffer_post_offset = NULL;
// ....
// Gets the data between offset and size
for(i = 0, data_block_n = start_at, position = 0, bytes_to_write = 0; data_block_n <= finish_at; ++data_block_n, ++i, position += bytes_to_write){
// Gets from disk the sector/block of data
if(Disk_Read(data_block_n, sector_str_data) == FAIL){
osErrno = E_GENERAL;
return FAIL;
}
// Calculates how many bytes are to be written
bytes_to_write = SECTOR_SIZE;
if(data_block_n == finish_at)
bytes_to_write -= inode.size - open_files_table.table[fd]->offset % SECTOR_SIZE;
// Gets more memory for the buffer
if((buffer_post_offset = (void *) realloc((void *) buffer_post_offset, (i + 1) * bytes_to_write * sizeof(char))) == NULL){
osErrno = E_GENERAL;
return FAIL;
}
// Writes into the buffer that store the data between offset and size
// GETTING THE WARNING ON THE NEXT LINE !!!!!!
if((memcpy((void *) buffer_post_offset + position, (void *) data_block_n, bytes_to_write)) == NULL){
osErrno = E_GENERAL;
return FAIL;
}
}
sizeof int可能不同于sizeofvoid*,请使用std::uintptptr\u t将指针保持在整数中。在memcpy中,是扇区str\u数据,而不是数据块 扇区数据是char*,所以根本没有警告 数据块是一个整数
<>真的很抱歉!< /p>什么是DATAABROBGN?我想这是一个整数,你为什么要这样做?太恐怖了!C还是C++?为什么那些长行不让我们滚动?!