Isthere any advantage in this practice comparedto my solution?Quote:
Originally Posted by quzah
Printable View
Isthere any advantage in this practice comparedto my solution?Quote:
Originally Posted by quzah
Yes, quzah's solution will actually return the array. Your suggestion will not do that.
But the compiled code doesn't know it is a string when returningQuote:
Originally Posted by Tonto
variables,, it just knows the lenght of a variable and pushs
that much data on to the stack so the data must be of a fixed
not variable lenght.
I see loads of poor programmers passing data about which should obviously be global.
When returning a string you are returning a pointer. Return values aren't placed on the stack they are returned in CPU registers. On x86 systems that's either a 32 bit value (EAX) or 64 bit value (EDX:EAX).
> Isthere any advantage in this practice comparedto my solution?
static arrays have the problem of what to do if the answer doesn't fit.
allocated memory has the problem of telling the caller that the memory needs to be freed.
Make the caller pass a pointer to where the answer is to be stored, and it's length.
This makes the function really easy to write. The caller is free to choose any kind of array or allocated memory approach it wants to, and the service function just does it's stuff.
> I see loads of poor programmers passing data about which should obviously be global.
Boy am I glad I don't have to maintain any of your code.
However the OP was concerned with returning as string,Quote:
Originally Posted by Quantum1024
not a string pointer. If you had a string 2000 bytes long I think
you would be scratchinig around for spare registers!!
esbo can you please give an example of a c function that returns a "string" and not a char *
Quote:
Originally Posted by spydoor
Well as I am explaining why it can't be done that puts me
in a rather tricky situation ;) :p