Otherwise
Description
The fallback arm of a Match. Runs iff no earlier arm matched.
Success
Body runs at most once, only when every preceding arm missed.
Failure
Macro cannot fail. Usable only inside a Match.
Usage example (Cross-references)
Usage examples (Cross-references)
- In
Variant.c:75:
When(Number, int) ok = false;
When(Number, double) ok = (it == 3.0);
Otherwise ok = false;
}
return ok;- In
Variant.c:110:
When(Number, int) count++;
When(Number, double) count++;
Otherwise count++;
}
return count == 1;- In
Variant.c:120:
bool deadend_variant_nonexhaustive(void) {
Number n = Number_from_double(9.0); // holds double, only int handled, no Otherwise
Match(n) {
When(Number, int)(void) it;- In
TypeMatch.c:24:
When(int) tag = 0;
When(double) tag = 1;
Otherwise tag = 9;
}
bool ok = tag == 0;- In
TypeMatch.c:31:
When(int) tag = 0;
When(double) tag = 1;
Otherwise tag = 9;
}
ok = ok && tag == 1;- In
TypeMatch.c:39:
When(int) tag = 0;
When(double) tag = 1;
Otherwise tag = 9;
}
ok = ok && tag == 9;- In
TypeMatch.c:78:
When(int) count++;
When(double) count++;
Otherwise count++;
}
return count == 1;- In
TypeMatch.c:89:
When(int) hit = false;
When(double) hit = false;
Otherwise hit = true;
}
return hit;- In
TypeMatch.c:123:
Position2D p = {1.0f, 2.0f};
Match(p) {
When(int)(void) it; // never matches Position2D, and there is no Otherwise
}
return true; // unreachable -- the match aborts first
- In
TypeMatch.h:75:
#define Match(x) \
for (bool MisraMatched = false, UNPL(tm_once) = true; UNPL(tm_once); UNPL(tm_once) = false, \
ASSERT_OR_FATAL(MisraMatched, "Match: no arm matched and no Otherwise (non-exhaustive)")) \
for (TYPE_OF(x) MisraSubject = (x), *UNPL(tm_loop) = &MisraSubject; UNPL(tm_loop); UNPL(tm_loop) = NULL)
Last updated on