avr-gcc-list
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [avr-gcc-list] issues with struct and volatile


From: klaas
Subject: Re: [avr-gcc-list] issues with struct and volatile
Date: Fri, 24 Jul 2009 08:26:01 +0200
User-agent: Thunderbird 1.5.0.14 (Windows/20071210)


Try this:

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

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


Declare the pointer volatile, not the value it is pointing to

Pink Boy wrote:
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
address@hidden
http://lists.nongnu.org/mailman/listinfo/avr-gcc-list







reply via email to

[Prev in Thread] Current Thread [Next in Thread]