Good News Everybody!
The new search engine is LIVE!
Please report any problems to david (at) midrange.com.
|
Hello,
I have the following RPG program that is calling a C function, but all i get back is a Null each time. If i put it in debug mode i can see that the value of chkdigit is correct, but then, when i get it back in my RPG, the value is NULL.
char* Pr_ChkDigit(char *str) {
char chkdigit; char* check_bit;
Now look at the code that uses them:
//Calcuations // Get checkbit from the Mapping Matrix chkdigit=reverse_map(c1,c2) ;
Okay, this changes the value of chkdigit.
*check_bit = chkdigit;
return check_bit;
And now you're returning the pointer, which will usually be NULL.
Now let's talk about your RPG program :)
D Pr_ChkDigit PR * ExtProc('Pr_ChkDigit') D * Options(*string) value
D Wrk_Str s 36A D Wrk_Null s 1A Inz(X'00') D Wrk_ChkDigit s 1A D Ptr_ChkDigit s * INZ(%ADDR(Wrk_ChkDigit))
/Free Wrk_Str = '70500607050AEI02x' + Wrk_Null; Ptr_ChkDigit = Pr_ChkDigit(%Addr(Wrk_Str)); Dsply Wrk_ChkDigit; *InLr = *on; /End-Free
You probably intended to do the following:
D Ptr_ChkDigit s *
D Wrk_ChkDigit s 1A based(Ptr_ChkDigit) D Ptr_ChkDigit s *
D Wrk_ChkDigit s 1A based(Ptr_ChkDigit) Ptr_ChkDigit = %alloc(1);
Wrk_ChkDigit = something;
dealloc Ptr_ChkDigit;is the same as:
char *ptr_chkdigit;
ptr_chkdigit = malloc(1);
*ptr_chkdigit = something;
free(ptr_chkdigit);And the following two code snippets are likewise the same:
D Ptr_ChkDigit s * inz(%addr(WrkChkDigit))
D Wrk_ChkDigit s 1AWrk_ChkDigit = something;
is the same as:
char wrk_chkdigit;
char *ptr_chkdigit; ptr_chkdigit = &wrk_chkdigit;
wrk_chkdigit = something;As an Amazon Associate we earn from qualifying purchases.
This mailing list archive is Copyright 1997-2026 by midrange.com and David Gibbs as a compilation work. Use of the archive is restricted to research of a business or technical nature. Any other uses are prohibited. Full details are available on our policy page. If you have questions about this, please contact [javascript protected email address].
Operating expenses for this site are earned using the Amazon Associate program and Google Adsense.