4 ms·
I've only seen flow control used in the context of conditional branching, so if the function contains no branches, I don't see why it would. Hidden overhead or
by dymk 3y ago
I've only seen flow control used in the context of conditional branching, so if the function contains no branches, I don't see why it would. Hidden overhead or indirection, sure, but not necessarily flow control, for the same reason e.g. indirect pointer access isn't.
- PH95VuimJjqBqy 3y agofunction calls are, themselves, branches. underneath there is literally assembly to take current state, push it to the stack, then jump into another location in memory and start executing. And then when done, do the reverse. jump back to another memory location and pop everything back off the aforementioned stack and into registers.
- dymk 3y agoYes, but that's not a conditional branch, and that's the distinction I've always seen made for flow control versus indirection
- PH95VuimJjqBqy 3y agotry/catch/finally is also considered control flow and it's not conditional, although, unfortunately I've seen people use it as a control flow mechanism. interrupts are also control flow but, again, there are no conditionals there. control flow is about the order of execution, one common way to get there is using conditionals, but it's not the only way. Having said that, even if you disagree with Andrew's wording, the overarching idea remains. You always know explicitly if the flow changes.
- Akronymus 3y agotry/catch seems very conditional to me. If there is an error condition, jump to the error handling code. Or am I missing something?
- PH95VuimJjqBqy 3y agoI could also describe a JMP instruction as "if you got here, jump to there", but just because I can doesn't necessarily mean I should.
- epcoa 3y agoBut Try, catch and throw are in themselves not conditional, they are fancy gotos with bookkeeping. Those constructs don’t typically deal with conditions. However I think the notion that “flow control” has to do only with conditionals is not a common one. FWIW the definition on Wikipedia, which aligns with my experience is not this restrictive… the lowly goto is flow control. Basically anything that controls the program location is flow control.
- Akronymus 3y agoYeah, but raising the error is the conditional in there. Which, to me, makes the try catch conditional as well, but that may be a case of differing semantics. Yeah, flow control isn't just conditional jumps. You can kinda treat branchless code as a form of flow control as well.
- PH95VuimJjqBqy 3y ago> You can kinda treat branchless code as a form of flow control as well. That's the common understanding of flow control, the other poster is right in that it's not typically just conditionals. There are a few posters who were under that misapprehension, but that's never been the common understanding of it, it's just that conditionals are typically where people worry over flow control because otherwise it's linear.
- epcoa 3y agoI haven’t usually used such a restrictive definition, flow control is any mechanism that directs program location. https://en.wikipedia.org/wiki/Control_flow https://en.wikipedia.org/wiki/Control_flow And flow control and indirection are not two concepts I’ve ever grouped together as complementary either. A function call is not something I’ve ever heard as “indirection”.