Hi,

I recently run into an issue with a struct with some volatile members and 
was wondering is this is a problem with me or gcc, ar avr-gcc.

I have a structure used to define a buffer for a serial port somewhat like
this.

struct
{
   uint8_t *tx_head;
   volatile uint8_t *tx_tail;
   uint8_t tx_buffer[DBG_BUF_SZ];

   /* blah blah */
   uint8_t dbg_timer;
} dbg_serial_port;

In my main loop I have a code that waits to see if the buffer is full.

     while(dbg_serial_port.tx_head == dbg_serial_port.txtail)
          ;

And of course with compiler flags set to optimize for size -Os it hangs
and waits forever.

The only way to get it to work is to declare the whole structure and 
tx_tail as volatile.  I'd be just annoyed, but if I do that I get a whole
bunch of compiler warnings on stuff like

uint8_t *temp = dbg_serial_port.tx_head;

I can fix those with a cast but doing that is like going after a fly 
with a hammer.

Is this a bug with gcc's handling of volatile or just me?

PS: Using the WinAvr 20090313.

Matt


_______________________________________________
AVR-GCC-list mailing list
AVR-GCC-list@nongnu.org
http://lists.nongnu.org/mailman/listinfo/avr-gcc-list

Reply via email to