Skip to main content
MKork.2
Associate
June 29, 2022
Solved

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

  • June 29, 2022
  • 9 replies
  • 13850 views

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?

This topic has been closed for replies.
Best answer by Andrew Neil

@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 functions - which expect char, not uint8_t)

 

EDIT

 

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

 

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

 

9 replies

waclawek.jan
Super User
June 29, 2022

Declare Rx_Byte as array of uint8_t, not char.

​

JW​

MKork.2
MKork.2Author
Associate
June 29, 2022

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

Andrew Neil
Andrew NeilBest answer
Super User
June 29, 2022

@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 functions - which expect char, not uint8_t)

 

EDIT

 

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

 

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

 

A complex system that works is invariably found to have evolved from a simple system that worked.A complex system designed from scratch never works and cannot be patched up to make it work.
Nikita91
Lead II
June 29, 2022

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.

Andrew Neil
Super User
June 29, 2022

@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/

A complex system that works is invariably found to have evolved from a simple system that worked.A complex system designed from scratch never works and cannot be patched up to make it work.
Nikita91
Lead II
June 29, 2022

> i try to learn

It is very good.

Good luck and see you later.

MKork.2
MKork.2Author
Associate
June 29, 2022

Thank you Mr.

Andrew Neil
Super User
June 29, 2022

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

0693W000008y9fZQAQ.png

A complex system that works is invariably found to have evolved from a simple system that worked.A complex system designed from scratch never works and cannot be patched up to make it work.