[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
returning c string pointer to gforth
From: |
Garry Ogle |
Subject: |
returning c string pointer to gforth |
Date: |
Wed, 17 Mar 2021 11:37:05 +0000 |
User-agent: |
Mozilla/5.0 (X11; Linux x86_64; rv:78.0) Gecko/20100101 Thunderbird/78.8.1 |
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
- returning c string pointer to gforth,
Garry Ogle <=