Home/Support/Support Forum/returning a float from a BSP function
Welcome to Digi Forum, where you can ask questions and receive answers from other members of the community.

returning a float from a BSP function

0 votes
I am using NetOS 5.0 and GHS 3.5 I have added a function (read_float()) to the BSP which returns a float (i.e I rebuilt BSP etc). Using the debugger I can see that this function calculates the correct value. At my application level the returned float value is wrong. e.g. IN BSP float read_float(void) { float bv; ..... return(bv); // bv correct here } IN MY APP float bv; bv = read_float(); // bv is not correct ??? printf("%06.4f",bv); Both the BSP and my application project files are setup for as per the default settings that is "software float" and "big endian" Looking at the assembly it looks like the returned value is been trashed.
asked Jun 23, 2003 in NET+OS by shatman Community Contributor (109 points)

Please log in or register to answer this question.

2 Answers

0 votes
Michael,I've found that GreenHills won't give a compiler/linker error when an external function (one not in the same source file) is called without first being prototyped. Instead, it just assumes that the return value for the unknown function is an int. This means that the value shown in read_float will not be the same as the value shown in IN_MY_APP because IN_MY_APP is interpreting those four bytes as an int, not a float. The solution is to be sure that you add the line "float read_float(void);" at the top of the source file that calls read_float. This lets the compiler know what the proper return value is. I hope this helps, James Fegan
answered Jun 23, 2003 by anonymous
0 votes
thank you - I found the that for my application project the "function used w/o prototype" option was set to "silent" in the project options for "C language". So I changed this to "warning". This then gave the warning about the prototype and lots of other warnings even in code supplied by Netsilicon.
answered Jun 24, 2003 by shatman Community Contributor (109 points)
...