Suspicious pointer conversion

mikroC, mikroBasic and mikroPascal for PRO ARM® MCUs, supporting STM32, Tiva, Kinetis, & CEC devices
Post Reply
Author
Message
paddywac
Posts: 10
Joined: 17 Nov 2015 13:28

Suspicious pointer conversion

#1 Post by paddywac » 08 Jan 2020 19:50

I'm getting a 'suspicious pointer conversion warning' for the following code; it works OK and does what I want, but why the warning?

/*
Convert int16 to bytes
----------------------
*/
void int2Bytes(int16_t parameter, uint8_t *pMSB, uint8_t *pLSB)
{
uint8_t * addr;

addr = &parameter;
*pLSB = * addr;
*pMSB = *(addr+1);
}

Then in the calling function:
uint8_t MSB, LSB;

int2Bytes(accX, &MSB, &LSB);

[accX is defined earlier in the code]

Any ideas?

Thanks
Pete

User avatar
stefan.filipovic
mikroElektronika team
Posts: 1135
Joined: 18 Dec 2018 10:30

Re: Suspicious pointer conversion

#2 Post by stefan.filipovic » 09 Jan 2020 14:52

Hi Pete,

You get this warning message because of the difference between the addr type and the parameter type. Just define the pointer addr as int16_t * addr;, and you will no longer get this warning message.

Kind regards,
Stefan Filipović

paddywac
Posts: 10
Joined: 17 Nov 2015 13:28

Re: Suspicious pointer conversion

#3 Post by paddywac » 09 Jan 2020 16:14

Hi, yes that makes sense.

I was using uint8_t for addr because I wanted to access the memory as a byte, but yes, it makes sense that the compiler would question it. I'll change it and see.

I was going to use a Union instead, which seems neater but maybe not as efficient.

Thanks for the support.

Pete

Post Reply

Return to “ARM PRO Compilers”