Prototype for C function returning array of strings -
so, trying create nicely readable c
function prototype, returns me array of strings (ie char*
). closest came like:
const char * const *entrypoints() { static const char* arrays[] = {"test123", "test2"}; return arrays; }
however, don't 2 *
s in declaration, looks scary :) ... did not find way emphasize fact function returning array of strings ... using [] in function declaration leads funny compile errors (such 'entrypoints' declared function returning array const char* (entrypoints() [])
or expected unqualified-id before '[' token const char[]* entrypoints()
or const char*[] entrypoints()
... yes, compiler right in both cases), , google seems have no answer this... here am.
is there way declare function prototype in nicely readable manner (this go in public api) return array of c strings. not c++. c. plain old c. if not, have stick 2 star approach ... ie. char **
. not (obscurely) awkward, emphasize function returns array of strings. c strings :)
i don't 2
*
s in declaration
i feel sorry you, that's how declare return type of "array-of-pointers". array decays pointer first element, declaration way can accomplish what's needed.
what can instead return pointer array of strings:
const char *(*fn())[2] { static const char *arr[2] = { "foo", "bar" }; return &arr; }
Comments
Post a Comment