Yahoo Groups archive

AVR-Chat

Index last updated: 2026-04-28 22:41 UTC

Thread

structures in gcc

structures in gcc

2008-01-24 by john

I'm trying to declare a structure but I keep getting an error like this
or similar depending on were I try to put __attribute__.

error: expected '=', ',', ';', 'asm' or '__attribute__' before 'struct'

Does avr-gcc allow plain-old structures? How should I write this to get 
it to compile?

struct __attribute__ ((__packed__)) rb_fifo_struct_type 
{
    uint8_t *head;
    uint8_t *tail;
    uint8_t *dptr;
};
typedef struct rb_fifo_struct_type rbuff_t;

Re: [AVR-Chat] structures in gcc

2008-01-24 by Russell Shaw

john wrote:
> I'm trying to declare a structure but I keep getting an error like this
> or similar depending on were I try to put __attribute__.
> 
> error: expected '=', ',', ';', 'asm' or '__attribute__' before 'struct'
> 
> Does avr-gcc allow plain-old structures? How should I write this to get 
> it to compile?
> 
> struct __attribute__ ((__packed__)) rb_fifo_struct_type 
> {
>     uint8_t *head;
>     uint8_t *tail;
>     uint8_t *dptr;
> };
> typedef struct rb_fifo_struct_type rbuff_t;

Try: __attribute__ ((packed));

I think you should be doing:

struct rb_fifo_struct_type
{
     uint8_t *head __attribute__ ((packed));
     uint8_t *tail __attribute__ ((packed));
     uint8_t *dptr __attribute__ ((packed));
};
typedef struct rb_fifo_struct_type rbuff_t;

Re: structures in gcc

2008-01-24 by john

--- In AVR-Chat@yahoogroups.com, Russell Shaw <rjshaw@...> wrote:
>
> john wrote:
> > I'm trying to declare a structure but I keep getting an error 
like this
> > or similar depending on were I try to put __attribute__.
> > 
> > error: expected '=', ',', ';', 'asm' or '__attribute__' 
before 'struct'
> > 
> > Does avr-gcc allow plain-old structures? How should I write this 
to get 
> > it to compile?
> > 
> > struct __attribute__ ((__packed__)) rb_fifo_struct_type 
> > {
> >     uint8_t *head;
> >     uint8_t *tail;
> >     uint8_t *dptr;
> > };
> > typedef struct rb_fifo_struct_type rbuff_t;
> 
> Try: __attribute__ ((packed));
> 
> I think you should be doing:
> 
> struct rb_fifo_struct_type
> {
>      uint8_t *head __attribute__ ((packed));
>      uint8_t *tail __attribute__ ((packed));
>      uint8_t *dptr __attribute__ ((packed));
> };
> typedef struct rb_fifo_struct_type rbuff_t;
>

I get the same error with the __attribute__ assigned to the member 
vairables.

For some reason if I put a semi colon in front of the structure the 
error goes away.

;    //<------------
struct rb_fifo_struct_type
{
    uint8_t *head;
    uint8_t *tail;
    uint8_t *dptr;
};
typedef struct rb_fifo_struct_type rbuff_t;

Re: [AVR-Chat] Re: structures in gcc

2008-01-24 by Dave Hylands

Hi John,

> For some reason if I put a semi colon in front of the structure the
> error goes away.
>
> ;    //<------------
> struct rb_fifo_struct_type

Then some previous declaration is probably missing the semicolon. It
might even be in a different file (i.e. header file).

-- 
Dave Hylands
Vancouver, BC, Canada
http://www.DaveHylands.com/

Re: [AVR-Chat] Re: structures in gcc

2008-01-24 by Russell Shaw

john wrote:
> --- In AVR-Chat@yahoogroups.com, Russell Shaw <rjshaw@...> wrote:
>> john wrote:
>>> I'm trying to declare a structure but I keep getting an error 
> like this
>>> or similar depending on were I try to put __attribute__.
>>>
>>> error: expected '=', ',', ';', 'asm' or '__attribute__' 
> before 'struct'
>>> Does avr-gcc allow plain-old structures? How should I write this 
> to get 
>>> it to compile?
>>>
>>> struct __attribute__ ((__packed__)) rb_fifo_struct_type 
>>> {
>>>     uint8_t *head;
>>>     uint8_t *tail;
>>>     uint8_t *dptr;
>>> };
>>> typedef struct rb_fifo_struct_type rbuff_t;
>> Try: __attribute__ ((packed));
>>
>> I think you should be doing:
>>
>> struct rb_fifo_struct_type
>> {
>>      uint8_t *head __attribute__ ((packed));
>>      uint8_t *tail __attribute__ ((packed));
>>      uint8_t *dptr __attribute__ ((packed));
>> };
>> typedef struct rb_fifo_struct_type rbuff_t;
>>
> 
> I get the same error with the __attribute__ assigned to the member 
> vairables.
> 
> For some reason if I put a semi colon in front of the structure the 
> error goes away.
> 
> ;    //<------------
> struct rb_fifo_struct_type
> {
>     uint8_t *head;
>     uint8_t *tail;
>     uint8_t *dptr;
> };
> typedef struct rb_fifo_struct_type rbuff_t;

When compiling the same code in gcc for x86, i don't get any error. Must mean
something in avr-gcc that isn't implemented. Could try (i don't think it has the
effect you want tho):

struct rb_fifo_struct_type
{
      uint8_t *head;
      uint8_t *tail;
      uint8_t *dptr;
} __attribute__ ((packed));
typedef struct rb_fifo_struct_type rbuff_t;

Re: structures in gcc

2008-01-25 by john

--- In AVR-Chat@yahoogroups.com, "Dave Hylands" <dhylands@...> wrote:
>
> Hi John,
> 
> > For some reason if I put a semi colon in front of the structure 
the
> > error goes away.
> >
> > ;    //<------------
> > struct rb_fifo_struct_type
> 
> Then some previous declaration is probably missing the semicolon. It
> might even be in a different file (i.e. header file).
> 
> -- 
> Dave Hylands
> Vancouver, BC, Canada
> http://www.DaveHylands.com/
>

Yeah, that was the problem.

Thanks.

Move to quarantaine

This moves the raw source file on disk only. The archive index is not changed automatically, so you still need to run a manual refresh afterward.