Please excuse me for asking C programming question in a C++ forum. As we know you can't return arrays from functions in programming language C. I am working on an open source code base written in C. While working on one of its function, I wanted to be sure if I have correctly understood the return value of the following function. Can someone please help me understand what exactly below functionbucket_straw2_choose is returning?
it returns one integer, specifically, bucket->h.items[high];
h.items may be an array but the index pulls one value out.
__s32 looks like a signed 32 bit integer, which is maybe what 'int' means on your compiler, but its safer to check that int == 32 bit vs 64 bit if you want to be very careful. A 32 bit int can be returned into a 64 bit anyway, but watch for such things; the code may make an unsafe assumption here depending on what you do next.
you can return arrays, but not directly.
you can return a pointer, in which case you need to ensure the array behind it is still alive (not destroyed when the function ended!) or you can return a struct that holds an array, and there are other tricky ways to get the job done. Don't let the syntax hold you back, C can do a LOT with a little.
there are already about 50 ways to say 'int' in C/C++. If you (or whoever wrote this) created that __S32 nonsense, get rid of it and use standard ones (int32_t for example). The __ makes me think to blame M$ but I am not going to look it up. If its a standard C thing, you can ignore me, I haven't done C pure in a while.
There is nothing quite so annoying and frustrating than seeing an answer very similar to the one already posted elsewhere. So while you're getting duplicate answers, someone else is either getting answers later, fewer answers or no answer at all - because that time got burned on your question.
As a courtesy, you should post your own cross references so people don't waste their time blindly.
all fine now....I agree what you said. I will avoid cross-post. And if in any case I do put the same question in two forums (which will not happen frequently), I will clearly mention that it has been already posted in another forum.