Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adding native C library functions - Passing pointers as float* #155

Open
GoogleCodeExporter opened this issue Oct 14, 2015 · 2 comments
Open

Comments

@GoogleCodeExporter
Copy link

What steps will reproduce the problem?
1. add in your library host this function 

float testParams(char myChar,int myInt,float myFloat,char* myCharP,float* 
myFloatP,int* myIntP) {

    printf("myChar   = %c\n\r",myChar);
    printf("myInt    = %d\n\r",myInt);
    printf("myFloat  = %f\n\r",myFloat);
    if (myCharP)
      printf("myCharP  = %c\n\r",*myCharP);
    if (myFloatP)
      printf("myFloatP = %d\n\r",*myFloatP);
    if (myIntP)
      printf("myIntP   = %d\n\r",*myIntP);

    *myCharP = myChar;
    *myFloatP = myFloat;
    *myIntP = myInt;

    return (float)1.23456;
}

2. add also this callback function

void CTestParams(struct ParseState *Parser, struct Value *ReturnValue, struct 
Value **Param, int NumArgs)
{
        char* myChar = (char*)Param[3]->Val->Pointer;
    float* myFloat = (float*)Param[4]->Val->Pointer;
    int* myInt = (int*)Param[5]->Val->Pointer;

    ReturnValue->Val->FP = testParams(Param[0]->Val->Character,
                                      Param[1]->Val->Integer,
                                      (float)Param[2]->Val->FP,
                                      myChar,
                                      myFloat,
                                      myInt);
}


3. and in platform library add the new library function and prototype
...
    { CTestParams,  "float testParams(char,int,float,char*,float*,int*);" },
...

4. run pico and test this code
char myChar='N'; 
float myFloat=123.456; 
int myInt=654; 
testParams('A',123,456.789,&myChar,&myFloat,&myInt); 
printf("myChar= %c\n\r",myChar); 
printf("myFloat= %f\n\r",myFloat); 
printf("myInt= %d\n\r",myInt);

What is the expected output? What do you see instead?

Expected result:
myChar= A
myFloat= 456.789
myInt= 123

Result:
myChar= A
myFloat= some random value....
myInt= 123

What version of the product are you using? On what operating system?
2.2 beta

Please provide any additional information below.

Original issue reported on code.google.com by [email protected] on 9 Feb 2012 at 7:29

@GoogleCodeExporter
Copy link
Author

please correct in testParams function
      printf("myFloatP = %d\n\r",*myFloatP); 
with
      printf("myFloatP = %f\n\r",*myFloatP);

Anyway this is not the solution of the problem, since the issue is present in 
the pointer parameter ;-)

Original comment by [email protected] on 9 Feb 2012 at 11:04

@GoogleCodeExporter
Copy link
Author

this issue is solved;
instead of 
float* myFloat = (float*)Param[4]->Val->Pointer;
use
double* myFloat = (double*)Param[4]->Val->Pointer;

Float pointer params are always treated  as double pointer param.

Original comment by [email protected] on 2 Apr 2013 at 6:38

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant