| ||||||||
Technical Support Support Resources Product Information | C51: DATA OVERLAYING PROBLEM WITH STRUCT PARAMETERSInformation in this article applies to:
SYMPTOMWhen 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);
}
CAUSEstructs 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. RESOLUTIONFunctions 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 µVision, the arguments of the OVERLAY directive are entered under Project - Options - Linker Misc. MORE INFORMATION
Last Reviewed: Tuesday, November 29, 2005 | |||||||
| ||||||||