ARM Technical Support Knowledge Articles

WRONG CODE WITH BIT-FIELD WIDTH EQUAL TO BASE TYPE

Applies to: C166 C Compiler

Answer


Information in this article applies to:


SYMPTOM

Post and pre increment operations on bit-fields generates invalid code when the bit-field width is identical to the underlaying data type.

Example:

struct {
  unsigned int  ibit_field :16;
  unsigned char cbit_field :8;
} test;

void increment_test (void)  {
  test.ibit_field += 1;      // correct code
  test.ibit_field ++;        // incorrect code

  test.cbit_field += 1;      // correct code
  test.cbit_field ++;        // incorrect code
}

CAUSE

Due to a C166 C Compiler problem, incorrect code has been generated up to Version 5.03.

RESOLUTION

Remove the bit-field width on the data definition. Since the width is identical to the data type it makes no sense to specify it. The modifications are shown in the example code below:

struct {
  unsigned int  ibit_field;
  unsigned char cbit_field;
} test;

void increment_test (void)  {
  test.ibit_field += 1;      // correct code
  test.ibit_field ++;        // correct code

  test.cbit_field += 1;      // correct code
  test.cbit_field ++;        // correct code
}

STATUS

The problem is corrected in future Version 5.05 (and later) version of the C166 Compiler. You may download the latest updates from the Keil Website.

Article last edited on: 2005-05-20 11:01:20

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