Assigning structure Error

General discussion on mikroC.
Post Reply
Author
Message
junqin_lau
Posts: 8
Joined: 14 Jul 2007 02:10

Assigning structure Error

#1 Post by junqin_lau » 19 Jul 2007 15:42

Code: Select all

typedef struct {
  prescaler  : 2;
  timeronoff : 1;
  postscaler : 4;} mybitfield;

// Declare a bit field TimerControl:
mybitfield TimerControl;

void main() {
  TimerControl.prescaler  = 0;
  TimerControl.timeronoff = 1;
  TimerControl.postscaler = 3;
  T2CON = TimerControl;
}

The error message encounter:

Cannot assign[TimerControl] to [T2CON]

The above code i get it from the help file in mikroC(struct)


Please kindly advise what went wrong with the above code.

User avatar
srdjan
mikroElektronika team
Posts: 1552
Joined: 28 Dec 2005 12:47
Location: Serbia

Re: Assigning structure Error

#2 Post by srdjan » 20 Jul 2007 09:08

Hi,
junqin_lau wrote:

Code: Select all

typedef struct {
  prescaler  : 2;
  timeronoff : 1;
  postscaler : 4;} mybitfield;

// Declare a bit field TimerControl:
mybitfield TimerControl;

void main() {
  TimerControl.prescaler  = 0;
  TimerControl.timeronoff = 1;
  TimerControl.postscaler = 3;
  T2CON = TimerControl;
}

The error message encounter:

Cannot assign[TimerControl] to [T2CON]

The above code i get it from the help file in mikroC(struct)


Please kindly advise what went wrong with the above code.
Unfortunately, this is a error in our help file. We'll correct this. Thank you for reporting.
You should do the following in your code.

Code: Select all

T2CON = *(unsigned*) &TimerControl;

junqin_lau
Posts: 8
Joined: 14 Jul 2007 02:10

Assigning structure Error

#3 Post by junqin_lau » 21 Jul 2007 03:10

Thanks alot

Post Reply

Return to “mikroC General”