ARM Technical Support Knowledge Articles

PROBLEMS INITIALIZING BITFIELD WITH POINTER

Applies to: C51 C Compiler

Answer


Information in this article applies to:


QUESTION

I'm having trouble initializing a bitfield with the value of a pointer. The problem is that after the initialization, the value of the bitfield does not contain the pointer value. The following example program demonstrates this problem.

#include <reg51.h>
#include <stdio.h>

char xdata i _at_ 0x0300;

struct
  {
  unsigned addr : 13;
  unsigned flag1 : 1;
  unsigned flag2 : 1;
  unsigned flag3 : 1;
  }
tbl = {&i, 0, 1, 1};


void main (void)
{
SCON  = 0x50;
TMOD |= 0x20;
TH1   = 221;
TR1   = 1;
TI    = 1;

/*** This outputs the incorrect value ***/
printf ("tbl.addr=%4.4X
", (unsigned) tbl.addr);

tbl.addr = &i;

/*** This outputs the correct value ***/
printf ("tbl.addr=%4.4X
", (unsigned) tbl.addr);

while (1);
}

Note that while initializations do not work, the assignment does work correctly.

What's the problem here and is there a work-around?

ANSWER

This was a problem in C51 V7.06. It is corrected in the C51 V7.07 update.

Article last edited on: 2005-05-20 09:31:12

Rate this article

[Bad]
|
|
[Good]
Disagree? Move your mouse over the bar and click

Did you find this article helpful? Yes No

How can we improve this article?

Link to this article
Copyright © 2011 ARM Limited. All rights reserved. External (Open), Non-Confidential