ARM Technical Support Knowledge Articles

DATA OVERLAYING PROBLEM WITH STRUCT PARAMETERS

Applies to: C51 C Compiler

Answer


Information in this article applies to:


SYMPTOM

When a function receives two or more struct arguments and one of these arguments is the return value of another function, the data overlaying may fail.

Example:

typedef struct
{
  float real;
  float imag;
} CFLOAT;


CFLOAT cfloat_mul (CFLOAT x, CFLOAT y)  {
  CFLOAT result;

  result.real = (x.real * y.real) - (x.imag * y.imag);
  result.imag = (x.real * y.imag) + (x.imag * y.real);
  return (result);
}


CFLOAT Get_val (int v)  {
  CFLOAT val;

  val.real = v;
  val.imag = 0;
  return val;
}


void main (void)  {
  CFLOAT temp;

  temp = cfloat_mul(Get_val(1), Get_val(2));  // error due to data overlaying
  while (1);
}

CAUSE

structs are returned in fixed memory addresses. When the struct is used again as a parameter to another function, the parameter may overwrite the values in the return struct.

RESOLUTION

Functions that receive more than one struct parameter can be excluded from data overlaying using the overlay directive of the linker.

The following linker directive excludes the function cfloat_mul from data overlaying:

OVERLAY (* ! cfloat_mul)

Similar functions may be overlaid in a separate root. The following linker directive overlays the data of cfloat_mul and cfloat_add but ensures that the struct parameters of the individual functions are not overwritten:

OVERLAY (* ! (cfloat_mul, cfloat_add))

In uVision, the arguments of the OVERLAY directive are entered under Project - Options - Linker Misc.

MORE INFORMATION

Article last edited on: 2005-11-29 11:55:04

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