Pelles C forum
C language => Pocket PC and Smartphone questions => Topic started by: ks65 on February 14, 2012, 11:18:22 PM
-
Using PellesC 6.50.4 I develop a Pocket PC application (Windows Mobile 5.0). I have problems with function calls of double variables. I reduced the problems to the example:
double test(long i,long a,int b,double d)
Inside the function test() the value of d is 0.0 independent of the call. The variables a and b are used in the function. Otherwise there is no problem with d. The following examples work:
double test(long i,double a,long b,double d)
double test(long i,long a,long b,float d)
double test(long a,long b,double d)
Is the stack size for function parameters the problem? How can I solve the problem?
-
Please post the whole function...
-
#include <stdio.h>
double test(long i,long a,int b,double d)
{
printf("i=%d a=%ld b=%ld d=%f\n", i, a, b, d);
return d+b+a+i;
}
int main(int argc, char **argv)
{
printf("%f\n", test(2,5,10,3.5));
return 0;
}
-
Here comes the function:
double test(long i,long a,int b,double d)
{
if(a+b>1000)
return(-1111.11);
return(d*2.0);
}
-
I can not find any problem with this.
Post your main() program, please.
czerny
-
Here you find the complete test Pocket PC Application as attach.
-
Other than using %lf in your sprintf() call it should work...
Try it with just %f and see what happens.
-
Possible bug with optimization.
#define UNICODE
#define _UNICODE
#define WIN32_LEAN_AND_MEAN
#include <windows.h>
double test(long a, long b, int c, double d)
{
if (b + c > 1000)
return (-1111.11);
return (d * 2.0);
}
double test1(long a, long b, int c, double d)
{
return d;
}
double test2(long a, long b, int c, double d)
{
if (b > 1000)
return (-1111.11);
return d;
}
double test3(long a, long b, int c, double d)
{
if (c > 1000)
return (-1111.11);
return d;
}
int __cdecl WinMainCRTStartup(void)
{
double dbl = 1.0;
WCHAR str[200];
wsprintf(str, _T("test1: %f=%f"), dbl, test1(1,2,3,dbl));
OutputDebugString(str);
wsprintf(str, _T("test2: %f=%f"), dbl, test2(1,2,3,dbl));
OutputDebugString(str);
wsprintf(str, _T("test2: %f=%f"), dbl, test3(1,2,3,dbl));
OutputDebugString(str);
return 0;
}
Output where test3 fail:ODS: test1: 1.000000=1.000000
ODS: test2: 1.000000=1.000000
ODS: test2: 1.000000=0.000000
EDIT:test3:
[00011090] E92D4030 stmdb sp!, {r4, r5, lr}
[00011094] E1A04003 mov r4, r3 <- ? overwrite register
[00011098] E1A05004 mov r5, r4 <- ?
[0001109C] E3520FFA cmp r2, #3E8
[000110A0] DA000004 ble 000110B8
[000110A4] E59F0004 ldr r0, [pc, #+4] ; PC+8+4 = 000110B0
[000110A8] E59F1004 ldr r1, [pc, #+4] ; PC+8+4 = 000110B4
[000110AC] EA000003 b 000110C0
[000110B0] A3D70A3D bicges r0, r7, #3D000
[000110B4] C0915C70 addgts r5, r1, r0, ror ip
@294:
[000110B8] E1A00004 mov r0, r4
[000110BC] E1A01005 mov r1, r5
@293:
[000110C0] E8BD8030 ldmia sp!, {r4, r5, pc}
-
Common Tater: %f gives no solution, independent of sprintf or wsprintf
timovjl: Thank you for your suggestion to analyse the optimization
I solved the problem of my test application by switching off the speed optimization: -Ot -> -Ob1
This shows that there may be a bug in the compilers optimization for ARM code.