Код
// Static Variables
static unsigned char UART_RxBuf[UART_RX_BUFFER_SIZE];
static volatile unsigned char UART_RxHead;
static volatile unsigned char UART_RxTail;
static unsigned char UART_TxBuf[UART_TX_BUFFER_SIZE];
static volatile unsigned char UART_TxHead;
static volatile unsigned char UART_TxTail;
.......................
#pragma vector=USART0_UDRE_vect
__interrupt void USART0_TX_interrupt( void )
{
unsigned char tmptail;
// Check if all data is transmitted
if ( UART_TxHead != UART_TxTail ) <<<< Warning
{
......
Warning[Pa082]: undefined behavior: the order of volatile accesses is undefined in this statement
static unsigned char UART_RxBuf[UART_RX_BUFFER_SIZE];
static volatile unsigned char UART_RxHead;
static volatile unsigned char UART_RxTail;
static unsigned char UART_TxBuf[UART_TX_BUFFER_SIZE];
static volatile unsigned char UART_TxHead;
static volatile unsigned char UART_TxTail;
.......................
#pragma vector=USART0_UDRE_vect
__interrupt void USART0_TX_interrupt( void )
{
unsigned char tmptail;
// Check if all data is transmitted
if ( UART_TxHead != UART_TxTail ) <<<< Warning
{
......
Warning[Pa082]: undefined behavior: the order of volatile accesses is undefined in this statement
Переменные UART_TxHead , UART_TxTail, UART_RxHead, UART_RxTail проинициализированы 0 в uart_Init() до разрешения прерываний. Как правильно поступить в данном случае:
1) не обращать внимания на предупреждения
2) заблокировать выдачу сообщений
3) убрать volatile при объявлении этих переменных ?
Если убрать volatile в одной из сравниваемой переменной, то варнинги не выдает. Но не будет ли при этом проблем с оптимизацией?