I have to fill out some documentation regarding a C project i worked on. One topic is whether I used “unconditional jumps”.
As far as I know, a “break” statement counts as a jump. And I have a few of those that fire when a condition in a loop is met. Does that make it a “conditional jump”?
Another example is when there are standard “break” statements in a switch case, are those conditional or unconditional?
Basically, what constitutes an “unconditional jump” in C?
3
It is a matter of terminology.
IMHO, any break
, continue
, goto
, return
which is not in the body of an if
or else
or case
is an inconditional jump.
So obviously
if (foobar) goto somelabel;
is a conditional jump.
In
if (foobar) {
x = something();
y = other(x);
return;
}
I would believe that the return
is conditional. Some people might object that because of the previous statements it is not (and only the entire block is conditional)
BTW, I heard of “unconditional jump” more when speaking of machine code than everything else.
Read also about basic blocks
I believe that your bureaucracy is just asking you if you used goto
; you could ask your management or client about what is really meant. I feel sorry for you that you have to lose your time on such (IMHO stupid or useless) questions.
1
Conditional means it may not be followed depending on some condition. Unconditional means that is program flow reaches that point it always will continue at the target.
A if
and a switch
are a conditional jumps.
At the end of the then
clause of an if
is an unconditional jump to after the else
clause. break
s in a switch are also unconditional.
9