returning without ending the function?

Started by
14 comments, last by Lohrno 22 years, 2 months ago
Is it possible for a function to return a value without breaking out of the function? And if so, could I ask how? =D -=Lohrno
Advertisement
Not in c/c++. You'll have to call another function passing whatever values you want to pass.

Edited by - lessbread on February 25, 2002 1:00:27 AM
"I thought what I'd do was, I'd pretend I was one of those deaf-mutes." - the Laughing Man
maybe with some evil goto concotenation
Pass a value to the function by pointer, and then modify it from within the function. Unless your program involves multiple threads, or has some sort of time dependency along with another process (or something equally ignominious), I don''t know why you would need to, though.
ReactOS - an Open-source operating system compatible with Windows NT apps and drivers
Aww...you mean I have to use a reference =( I hate adding
parameters to my functions =(

And no, I''m not using any any goto lines sorry...I may be evil,
but thats just crossing the line!

-=Lohrno
umm... no params? How about a global var then? Why dont you describe what you are trying to accomplish?
quote:Original post by Lohrno
Aww...you mean I have to use a reference =( I hate adding
parameters to my functions =(

Get over it.

[ GDNet Start Here | GDNet Search Tool | GDNet FAQ | MS RTFM [MSDN] | SGI STL Docs | Google! ]
Thanks to Kylotan for the idea!
quote:Original post by Lohrno
Is it possible for a function to return a value without breaking
out of the function?


That doesn''t make any sense. If you haven''t "broken out of the function", then you haven''t returned. What is it that you are trying to achieve?

--

When horses lift their heads up high to look at something, they''re looking far into the distance. To see things that are closer, they lower their heads.
there is a problem though. You can only have one function running at a time. So If you want to check what value a funciton has returned from another function, you need to exit the first function so that you can run the second function, totally defeating your purpose. The reason is your processor can only execute on instruction at a time. With your functions being a list of instructions, you cannot have more than one list active at a time.p
The only possible way would be to have your functions run off of somekind of step-wise style that you could regulate from your main function.
In most cases, if there is something you want to do after you return the value you could just make another function to do that stuff.

...maybe dual processors might be able to get two functions running at the same time...

[Formerly "capn_midnight". See some of my projects. Find me on twitter tumblr G+ Github.]

It is possible to have multiple functions running "at the same time" (or to simulate the effect), using mechanisms such as threading or asynchronous function call. However, once a function returns, by definition it has completed. I suspect that, as often happens, the OP has a problem, and is assuming a particular solution rather than asking how to approach solving the problem.

--

When horses lift their heads up high to look at something, they''re looking far into the distance. To see things that are closer, they lower their heads.

This topic is closed to new replies.

Advertisement