ARM Technical Support Knowledge Articles

INCORRECT ACCESSING OF 2D ARRAY IN STRUCTURE

Applies to: C51 C Compiler

Answer


Information in this article applies to:


SYMPTOMS

I have written the following code:

typedef struct
{
  int step [2][4];
} STRIP_DATA_TYPE;

xdata STRIP_DATA_TYPE strip_data;
xdata STRIP_DATA_TYPE *strip_ptr = &strip_data;

void main (void)
{
  unsigned char step_num = 1, ndx = 3;

  strip_ptr -> step[step_num][ndx] = 0xAA;
}

Instead of step[1][3] being set to AAH, step[1][0] is set to AAH. Is this a bug?

CAUSE

Yes. However, a very specific set of conditions must be true for the compiler to generate the wrong code:

The following lines of code will all work in the Large memory model:

RESOLUTION

This bug is fixed in C51 v5.50e. To obtain this update see the Attachments section below.

ATTACHED FILES

Request the files attached to this knowledgebase article.

Article last edited on: 2007-03-27 17:10:16

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