Topic : Passing function parameter

Forum : 8051

Original Post
Post Information Post
May 17, 2007 - 10:10pm
Guest

I have a problem with this function:

...

at 0x0700 xdata unsigned char tmp_array[128];

...

void store_float_array(unsigned int address, unsigned int item, float value)
{
memcpy(&tmp_array[0], (unsigned char *)&eeprom_float[0], 128);
item *= 4;
*(float*)&tmp_array[item] = value;
store_temporary_array(EEPROM_FLOAT_ADDRESS);
}

anythings works fine except line:
item *= 4;

from unexplained reason this simple count doesnt work. But when I put estimated value directly to variable, everythings works fine.

After some experiments I found the solution and changed input parameter type from unsigned int to unsigned char as follows:

...

void store_float_array(unsigned int address, unsigned char item, float value)
{
memcpy(&tmp_array[0], (unsigned char *)&eeprom_float[0], 128);
item *= 4;
*(float*)&tmp_array[item] = value;
store_temporary_array(EEPROM_FLOAT_ADDRESS);
}

and everythings works fine with unsigned char.
Can you tell me where do I have mistake in code with 'unsigned int' type parameter?

Thank you at all Hupi

Replies
Post Information Post
+1
0
-1
May 18, 2007 - 6:07pm
Guest

1. Compare the assembler generated for the 2 code types
2. In the compiler code-generation options, do you have ANSI char->int promotion on or off?

Steven Pruzina

+1
0
-1
May 25, 2007 - 11:32pm
Guest

pruzis wrote:
1. Compare the assembler generated for the 2 code types
2. In the compiler code-generation options, do you have ANSI char->int promotion on or off?

Steven Pruzina


Hi Steven, thank you for your ideas. I dont have so much time to compare assembler codes, due to my exams season, but I will do this soon. What effect does "ANSI char->int promotion"? I had this switched to on in my project.

Thank you Michal Hupka