bit field access

Discuss about beta versions of mikroC compiler.
Post Reply
Author
Message
jpc
Posts: 1986
Joined: 22 Apr 2005 17:40
Location: France 87

bit field access

#1 Post by jpc » 25 Apr 2006 13:09

using bit field variables i found something strange :

Code: Select all

struct{
  counter : 4;
  status : 3;
  test   : 1;
  } myreg;

...

while(nn<7){
   (x[nn] = nn++);
   myreg.status ++;<<<<<<<<<<<<<<<<<<<<<<<<<<<<
    myreg.counter=myreg.counter+2;}
actually clears counter , add1 to counter and never stores anything in myreg.status.

if i change this to

Code: Select all

while(nn<7){
   (x[nn] = nn++);
   myreg.status = myreg.status + 1;;
    myreg.counter=myreg.counter+2;}
it is ok

jpc
Posts: 1986
Joined: 22 Apr 2005 17:40
Location: France 87

#2 Post by jpc » 25 Apr 2006 13:34

it looks as if == reads the value of myreg.status , increments it and then write back as normal byte/word/??? forgetting the offset in the struct
If i init the myreg.status with a value , this value , incremented by one is written in counter , leaving status cleared to zero , on the next pass in this loop myreg.status is read zero , incremented and rewritten to myreg.counter.

User avatar
rajkovic
mikroElektronika team
Posts: 694
Joined: 16 Aug 2004 12:40

#3 Post by rajkovic » 26 Apr 2006 09:44

jpc wrote:it looks as if == reads the value of myreg.status , increments it and then write back as normal byte/word/??? forgetting the offset in the struct
If i init the myreg.status with a value , this value , incremented by one is written in counter , leaving status cleared to zero , on the next pass in this loop myreg.status is read zero , incremented and rewritten to myreg.counter.
You are right we have located and fixed bug.

Post Reply

Return to “mikroC Beta testing”