returning c string pointer to gforth
Garry Ogle <[email protected]> Wed, 17 Mar 2021 11:37:05 +0000
| Newsgroups | gmane.comp.lang.forth.gforth |
|---|---|
| Message-ID | <[email protected]> |
My apologies in advance if this turns out to be a C programming question rather than a Gforth one: I'm a newbie to C (though not to Forth). I'm trying to return a pointer to a string from a C function so I can use the string in Forth. My string pointer ( in my latest attempt) is declared as a global variable: static char *text; The function that sets the pointer is declared thus: const char* XPaste( ) and the code that sets the pointer is: text=malloc(size+1); memcpy(text,data,size +1); return text; the function is defined in Forth as: c-function xpaste XPaste -- a My problem is that the address returned causes an "Invalid memory address" error when I try to access it. Where am I going wrong? Thanks in advance, Garry