简体   繁体   中英

Cast from uint8_t pointer to uint32_t integer compilation error

Following error shows while compilation process:

aes.c:267:35: error: cast from pointer to integer of different size [-Werror=pointer-to-int-cast]
    HWREG(AES_DMAC_CH0_EXTADDR) = (uint32_t)pui8MsgIn;

The lines 275-276:

// base address of the input data in ext. memory
HWREG(AES_DMAC_CH0_EXTADDR) = (uint32_t)pui8MsgIn;

pui8MsgIn is type of uint8_t * .

HWREG macro looks like this:

#define HWREG(x)                                                              \
        (*((volatile uint32_t *)(x)))

I am not experienced in C and its pointers, but presumably I could resolve it by changing uint32_t cast to uintptr_t . Is it correct?

I want to confirm that, because uintptr_t seems to not have any size in it's name contrary to uint32_t .

presumably I could resolve it by changing uint32_t cast to uintptr_t . Is it correct?

Yes. uintptr_t is specified to be an unsigned integer type wide enough to accommodate the result of the conversion of any pointer to an integer.

I want to confirm that, because uintptr_t seems to not have any size in it's name contrary to uint32_t.

That's the whole point (no pun intended). C does not specify how big a pointer is, and in fact that varies between implementations. You can't specify a particular size in the type name if you must accommodate all implementations' pointers.

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