cancel
Showing results for 
Search instead for 
Did you mean: 

Accessing single bits

drumfirex
Associate II
Posted on July 01, 2003 at 07:03

Accessing single bits

3 REPLIES 3
drumfirex
Associate II
Posted on June 30, 2003 at 07:19

I use Codewarrior compiler and I want to access bits in this way:

typedef struct Type_AnIn {

signed short Value;

unsigned char Ampli :4;

unsigned char Status :4;

};

struct Type_AnIn AnIn; /* size: 3 bytes */

void Test(void)

{

unsigned char Aux;

/* Example */

AnIn.Ampli = 3; /* write access --> warning */

AnIn.Status = 0; /* write access --> warning */

AnIn.Value = -20; /* no warning */

AnIn.Status = 0; /* write access --> warning */

Aux = AnIn.Ampli; /* read access --> no warning */

}

The compiler generate the following message only when I tried to write bit access structure fields:

C3604 Static '_xxPSID1' was not referenced.

I think.......there is something wrong

Thanks, Patrik

parveen
Associate II
Posted on July 01, 2003 at 02:24

I tried to run similar code on Hiware Compiler and there is no problem with bitfield operation.

There may be some other problems in the code

Regards,

PraveenG
drumfirex
Associate II
Posted on July 01, 2003 at 07:03

You are correct, I omit some informations because I thought the ''error'' happened anyway....sorry.

The code is like this:

struct Type_AnIn AnIn[3];

void Test(void)

{

unsigned char Ix;

for (Ix = 0; Ix < 3; Ix++)

AnIn[Ix].Ampli = AMP_NTC;

}

When I select the ''error'' to point the code that generates it, the Codewarrior highlight the line above header of the next function....

The ''problem'' doesn't occur if I use:

AnIn->Ampli = AMP_NTC;

The ''problem'' doesn't occur if I use:

typedef struct Type_AnIn {

signed short Value;

unsigned char Ampli;

unsigned char Status:4;

};

If I open the map file, I see that when I access a bit mapped field the compiler generates a variable (_xxPSID1) in the overlap segment.

C3604 is not an error nor a warning, it's only an ''information'' message...but I want to know why...

Thanks for your help,

Patrik