cancel
Showing results for 
Search instead for 
Did you mean: 

Warning: pointer targets in passing argument 2 of 'HAL_UART_Receive' differ in signedness [-Wpointer-sign]

MKork.2
Associate II

Hi everyone, i see a warning when i write the code;

-->   HAL_UART_Receive(&huart3, &Rx_Byte[0], 1, 10);

Rx_Byte is;

-->  char Rx_Byte[1];

Why i see this warning can anyone help me?

1 ACCEPTED SOLUTION

Accepted Solutions

@MKork.2​ "because of i am new on stm. Why uint8_t ?"

It has nothing specifically to do with STM - this is standard C stuff:

  • As the name suggests, uint8_t is unsigned;
  • Whether plain char is signed or not is implementation-defined.

You are correct in using char for plain, printable ASCII text - that is what it's for.

However, HAL_UART_Receive() is not restricted to plain text; it handles any arbitrary byte values - hence it uses uint8_t.

You could suppress the warning by casting your char value; eg,

char my_char;
 
HAL_UART_Receive( &huart3, (uint8_t*)&my_char, 1, 10 );

Or you could just make it uint8_t (though you may then get the same warning from C standard string function - which expect char, not uint8_t)

EDIT

https://en.cppreference.com/w/cpp/types/integer

https://en.wikipedia.org/wiki/C_data_types

View solution in original post

9 REPLIES 9

Declare Rx_Byte as array of uint8_t, not char.

JW​

Thank you but i will take a char from keyboard. Sorry because of i am new on stm. Why uint8_t ?​

@MKork.2​ "because of i am new on stm. Why uint8_t ?"

It has nothing specifically to do with STM - this is standard C stuff:

  • As the name suggests, uint8_t is unsigned;
  • Whether plain char is signed or not is implementation-defined.

You are correct in using char for plain, printable ASCII text - that is what it's for.

However, HAL_UART_Receive() is not restricted to plain text; it handles any arbitrary byte values - hence it uses uint8_t.

You could suppress the warning by casting your char value; eg,

char my_char;
 
HAL_UART_Receive( &huart3, (uint8_t*)&my_char, 1, 10 );

Or you could just make it uint8_t (though you may then get the same warning from C standard string function - which expect char, not uint8_t)

EDIT

https://en.cppreference.com/w/cpp/types/integer

https://en.wikipedia.org/wiki/C_data_types

Nikita91
Lead II

Look at the declaration of the HAL_UART_Receive() function. You will see that this argument asks for a pointer to uint8_t and not a pointer to char.

It seems that you are new to STM, but also to the C language. Start with a C training will be very profitable.

@Nikita91​ "It seems that you are new to STM, but also to the C language. Start with a C training will be very profitable"

+1

Also, it's likely easier to learn the C language on a "normal" platform such as a PC - away from all the added complications & restrictions of small embedded microcontrollers.

Once you've learned the language, then you can move on to applying it to small embedded microcontrollers...

Here's some C learning & reference materials - including a free online textbook:

https://blog.antronics.co.uk/2011/08/08/so-youre-thinking-of-starting-with-c/

thank you for answer. Yes i am new to STM and also C but i try to learn.

Nikita91
Lead II

> i try to learn

It is very good.

Good luck and see you later.

Thank you Mr.

@MKork.2​  If your issue is now resolved, please mark the solution:

0693W000008y9fZQAQ.png