"no*********@gmail.com" <no*********@gmail.comwrites:
Why is it not possible to return char** from a funcion. For example:
char** foo(void) {
char[][] foobar = {"foo", "bar"};
return foobar;
}
There are at least three problems here. First, char[][] is not a
valid type. Only the first in a sequence of array declarators
may have empty brackets.
Second, if it were a valid type, char[][] would not be the same
type as char **. The name of an array used in an expression is,
in most circumstances, converted to a pointer to its first
element, which in this case would result in type "char (*)[]",
that is, a pointer to an array. A pointer to an array is not
compatible with a pointer to a pointer.
P.S. Is there anyway to get rid of that pesky "function returns adress
of local variable" warning?
Third, you're trying to return the address of a local variable.
The correct thing to do is to not return the address of a local
variable. One way to do that would be to declare the array
"static", but I'd recommend doing that only if its value never
changes, in which case "const" might also be warranted.
Alternatively, you could dynamically allocate your array.
--
"For those who want to translate C to Pascal, it may be that a lobotomy
serves your needs better." --M. Ambuhl
"Here are the steps to create a C-to-Turbo-Pascal translator..." --H. Schildt