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

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

Re: [avr-gcc-list] Problem with union


From: Ned Konz
Subject: Re: [avr-gcc-list] Problem with union
Date: Mon, 23 Aug 2004 06:51:00 -0700
User-agent: KMail/1.6.2

On Monday 23 August 2004 5:23 am, Eric Fu wrote:
> I have a problem to use union in avrgcc. When I compile the following,:
> typedef union TwoBytes
> {    /* unsigned 16 bit type for 8 & 16 */
>  word wForm;   /* bit accesses: 16 bit var.wForm    */
>  struct
>  {   /* 8 bit var.byForm.High/Low          */
>   byte High;
>   byte Low;
>  }byForm;
> }TwoBytes;
>
>
> TwoBytes ThisNodeID;
> ThisNodeID.wForm = 1;
>
> I get compiling error:
>
> error: parse error before '.' token
>
> What Did I do wrong?

Probably used #define for the definition of 'word' , instead of a typedef like 
you should have done.

Using the standard typedefs, your code compiles just fine:

// avr-gcc -mmcu=atmega16  -Wall xx2.c

#include <inttypes.h>
#include <avr/io.h>

typedef union TwoBytes
{                               /* unsigned 16 bit type for 8 & 16 */
    uint16_t wForm;             /* bit accesses: 16 bit var.wForm    */
    struct
    {                           /* 8 bit var.byForm.High/Low          */
        uint8_t High;
        uint8_t Low;
    } byForm;
} TwoBytes;


int main(int argc, char const * const * argv)
{
    TwoBytes ThisNodeID;

    ThisNodeID.wForm = 1;

    return 0;
}

-- 
Ned Konz
http://bike-nomad.com



reply via email to

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