简体   繁体   中英

getting an warning cast to pointer from integer of different size

I am currently working on porting from 32 bit to 64 bit. And I am getting a warning:

cast to pointer from integer of different size

In the following code

AcLogFileWrite(
    (FILE *) pOut->pTrace->logFileHandle, /* warning in this line */
    outRecord,
    outRecordLen);

and prototype of AcLogFileWrite() is

int AcLogFileWrite(
    FILE * handle,
    char * data,
    int    bytes);

Here the parameter pOut->pTrace->logFileHandle is of type int .

How can I fix this warning?

You can't store 64 bits in a 32-bit int. If logFileHandle has to store a pointer, the only integer types that can safely do that are uintptr_t or intptr_t from <stdint.h> . Or you can typedef void* . Since you're porting to a new ABI anyway, binary compatibility is not an issue and this is a good time to fix it.

If you absolutely cannot change the definition of the type from int , then you must compile under the ILP64 model, in which int , long and void* are all 64 bits wide.

如果logFileHandle实际上是使用例如open()初始化的文件描述符, fdopen在其上使用fdopen并将函数的结果传递给AcLogFileWrite()

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM