API Reference — status/StatusCode
StatusCode
Pair a numeric status code with a human-readable message for results that need both machine-checkable identity and a displayable reason.
Why this exists
Raw integer codes force callers to do a separate lookup to get a diagnostic string, while raw strings make programmatic comparison fragile. StatusCode solves both: equality is always code-based, so dispatch and matching stay numeric, while message is available directly for logging or display. The SCAPI export macro signals that this type crosses a shared-library boundary, making the plain-struct layout intentional.
Fields
| Name | Type | Description |
|---|---|---|
code |
int |
required — numeric identifier for the status condition. All equality and comparison operations are based solely on this field. |
message |
const char* |
required — human-readable description of the status. Does not own the pointed-to string; must point to a stable allocation or string literal. |
Construction
// Aggregate-initialise with a stable string literal
sc::StatusCode ok = {0, "OK"};
sc::StatusCode fail = {1001, "Joint count mismatch"};
// Compare by code
if (result != ok) {
fprintf(stderr, "Error %d: %s\n", result.code, result.message);
}
Relationships
operator==— free function innamespace sc; returnstruewhen both operands share the samecode, regardless ofmessage.operator!=— free function innamespace sc; logical negation ofoperator==.
Constraints
- Equality is code-only. Two
StatusCodevalues with the samecodebut differentmessagestrings are considered equal byoperator==. Do not usemessagecontent as an identity signal.
Watch out for
messageis a rawconst char*with no ownership. Pointing it at a temporarystd::string::c_str()or a local buffer produces a dangling pointer. Always use a string literal or a heap allocation whose lifetime exceeds theStatusCode.