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
TypeMatch.h:79:
#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)- In
Variant.c:75:
When(Number, int, v) ok = false;
When(Number, double, v) ok = (v == 3.0);
Otherwise ok = false;
}
return ok;- In
Variant.c:110:
When(Number, int, v) count++;
When(Number, double, v) count++;
Otherwise count++;
}
return count == 1;- In
Variant.c:117:
// Deadend: a non-exhaustive variant match aborts rather than fall through.
bool deadend_variant_nonexhaustive(void) {
Number n = Number_from_double(9.0); // holds double, only int handled, no Otherwise
Match(n) {
When(Number, int, v)(void) v;- In
TypeMatch.c:24:
When(int, v) tag = 0;
When(double, v) tag = 1;
Otherwise tag = 9;
}
bool ok = tag == 0;- In
TypeMatch.c:31:
When(int, v) tag = 0;
When(double, v) tag = 1;
Otherwise tag = 9;
}
ok = ok && tag == 1;- In
TypeMatch.c:39:
When(int, v) tag = 0;
When(double, v) tag = 1;
Otherwise tag = 9;
}
ok = ok && tag == 9;- In
TypeMatch.c:78:
When(int, v) count++;
When(double, v) count++;
Otherwise count++;
}
return count == 1;- In
TypeMatch.c:89:
When(int, v) hit = false;
When(double, v) hit = false;
Otherwise hit = true;
}
return hit;- In
TypeMatch.c:122:
Position2D p = {1.0f, 2.0f};
Match(p) {
When(int, v)(void) v; // never matches Position2D, and there is no Otherwise
}
return true; // unreachable -- the match aborts first
Last updated on