D
Darshan
What should be the return type of a function returning an array of
pointers to a structure?
pointers to a structure?
Darshan said:What should be the return type of a function returning an array of
pointers to a structure?
No such function is possible in C, so its "return type"
is a type from some other language.
A C function might return a pointer to the first element
of an array. If the array's elements are of type `struct foo*',
a pointer to one of them (and the function's type) would be
`struct foo**'.
will not it result into pointer dangling?
bcoz the function stack frame will be deleted.
[email protected] (Richard Harter) said:Not directly, perhaps, but can't we wrap the array in a struct?
Modulo syntax errors something like
struct hack {
struct tgt *a[5];
};
struct hack foo(void) {
struct hack yecch;
/* Some sort of code */
return yecch;
Not directly, perhaps, but can't we wrap the array in a struct?No such function is possible in C, so its "return type"
is a type from some other language.
struct hack {
struct tgt *a[5];
};
If your 'struct hack' is a struct hack and you intent to return
more than 5 struct tgt pointers, realise you've only allocated
sizeof(struct hack) bytes. You can't write to yecch beyond
that limit.
Darshan said:What should be the return type of a function returning an array of
pointers to a structure?
Richard said:No such function is possible in C, so its "return type"
is a type from some other language.
Not directly, perhaps, but can't we wrap the array in a struct?
[...]
Eric Sosman said:No C function can return an array.
Want to reply to this thread or ask your own question?
You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.