JohnRobert wrote:Or is this not possible.
It is not. Your array "buffer" is a local variable of your function,
that is, an "automatic variable" in C parlance; when you leave the
function the variable no longer exists (it typically is allocated on
the stack, and its space will be automatically reused).
There are two typical ways to handle your problem:
1) Pass an array to the function; it is then the caller's responsibility
to allocate it;
2) statically allocate it, either outside of your function or inside it.
It will then always take up space (which is not as bad as it sounds:
you need that space _anyway_, and you cannot usually timeshare it
with something else). There also then always is exactly one such
array, not one per function call, so you have to read its contents
and do what you want with it before calling the function again, since
it will overwrite it.
Code: Select all
char rxString(in port RXD, char *buffer[]){
That should be
I'm quite new to pointers, C syntax,
This isn't C, this is XC. An important difference is that you can
return an array, too! (In C, an array is sort-of the same as a pointer;
in XC, an array also "knows" its own length).
[...] Is this correct?
Yes, pretty much. Your use of "constructed" however suggests that
you want to allocate the space from some "heap" of memory. You do
not want to do that; memory is a finite resource, you want to more
carefully manage it, or else you will get out-of-memory problems
at runtime. Just allocate it statically :-)
Hope this helps,
Segher