[M3devel] returning an array from a function??

Jay jayk123 at hotmail.com
Sat Apr 5 21:02:01 CEST 2008


How does one return a constant array of unspecified size from a function?
You know, what might otherwise be a constant array in the interface, but I'd
rather hide it behind a function?


something like this, though I haven't found anything that compiles and runs:


PROCEDURE GetPathVariableNames(): REF ARRAY OF TEXT =
  BEGIN
    RETURN ARRAY OF TEXT {
(* not all of these presently have meaning but they are suggested synonyms *)
(*      0123456789012345 *)
(* 8*) "CM3_ROOT",   (* root of source tree *)
(* 8*) "M3CONFIG",
(*10*) "CM3_CONFIG", (* new unimplemented synonym for M3CONFIG *)
(*11*) "CM3_INSTALL",
(*11*) "INSTALLROOT",
(*12*) "INSTALL_ROOT",
(*14*) "CM3_SOURCEROOT",  (* new unimplemented synonym for CM3_ROOT *)
(*15*) "CM3_INSTALLROOT",
(*15*) "CM3_SOURCE_ROOT", (* new unimplemented synonym for CM3_ROOT *)
(*16*) "CM3_INSTALL_ROOT"
(*      0123456789012345 *)
};
  END GetPathVariableNames;



in C I would write:


char** GetWhatever()
{
 const static char* strings[] = { "abc", "def", 0 };
 return strings;
}



or


char** GetWhatever(size_t* Count)
{
 const static char* strings[] = { "abc", "def" };
 *Count = sizeof(strings)/sizeof(strings[0]);
 return strings;
}


The client doesn't have to know if it is constant or not.
It could be initialized at runtime, with a dynamic size, or not
I should not have to make a copy per call.


 - Jay

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://m3lists.elegosoft.com/pipermail/m3devel/attachments/20080405/2479107b/attachment-0001.html>


More information about the M3devel mailing list