Keil Logo

C166: Using sbit in Embedded C++


Information in this article applies to:

  • C166 Version 5
  • EC166 Version 1

QUESTION

I have used the sbit constructs in the C166 Compiler for several years and I am now converting my program to Embedded C++. It appears that the following construct does not work:

unsigned int bdata ival;
sbit b0 = ival^0;
sbit b1 = ival^1;
sbit b2 = ival^2;
sbit b3 = ival^3;

What can I do to achieve bit-level access in the Embedded C++ Compiler?

ANSWER

The Embedded C++ Compiler uses standard C syntax for this. Just rewrite your program, so it uses a bit-field that is located to the bdata memory type.

struct bits {
  unsigned int b0: 1;
  unsigned int b1: 1;
  unsigned int b2: 1;
  unsigned int b3: 1;
  unsigned int b4: 1;
  unsigned int b5: 1;
  unsigned int b6: 1;
  unsigned int b7: 1;
};

union bacc  {
  unsigned int uc;
  struct bits   b;
};

union bacc bdata v1;    // bdata variables can be accessed using bit instructions

int main()  {
  if (v1.b.b0) {
    v1.b.b1 = 1;
  }
}

SEE ALSO


Last Reviewed: Thursday, February 25, 2021


Did this article provide the answer you needed?
 
Yes
No
Not Sure
 
  Arm logo
Important information

This site uses cookies to store information on your computer. By continuing to use our site, you consent to our cookies.

Change Settings

Privacy Policy Update

Arm’s Privacy Policy has been updated. By continuing to use our site, you consent to Arm’s Privacy Policy. Please review our Privacy Policy to learn more about our collection, use and transfers
of your data.