c - 警告 : cast to pointer from integer of different size [-Wint-to-pointer-cast] c programming

标签 c warnings memcpy

我不明白为什么会触发这个警告!

test.c:920:56:警告:从不同大小的整数转换为指针 [-Wint-to-pointer-cast]

if((memcpy((void *)(buffer_post_offset + 位置), (void *) data_block_n, bytes_to_write)) == NULL){

这是一段代码...

    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) 可能与 sizeof(void*) 不同,使用 std::uintptr_t 将指针保存在整数中。

关于c - 警告 : cast to pointer from integer of different size [-Wint-to-pointer-cast] c programming,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26643151/

相关文章:

android - 使用OpenCV检测透视角度并进行透视变换

c++ - 删除显式默认函数声明时发出警告

php - "Notice: Undefined variable"、 "Notice: Undefined index"、 "Warning: Undefined array key"和 "Notice: Undefined offset"使用 PHP

c++ - 理解为什么它不能使用 memcpy 正确复制

c++ - 为什么 memcpy 不在导入表中?

c - 在 memcpy 中对齐源地址和目标地址

sql - C语言中的嵌入式sql

c - C 中的共享全局 Typedef 变量重新声明

c++ - GDB:仅当先前的中断在 func2 上时才在 func1 上中断

mysql - 将 mysql 表从 server1 上的一个数据库复制到 server2 上的另一个数据库