C Enums and typedef
Use an enum for review state and typedef to give a record a concise domain name.
How it works
An enum introduces named integer constants. It helps a reader understand that a value represents a state, although ordinary C enums do not prevent every out-of-range integer from reaching an interface. Validate external numeric values before interpreting them as states. typedef introduces another name for a type; it does not create a new type with automatic range checks. Choose aliases that explain the domain and avoid hiding pointer levels unless the API deliberately presents an opaque handle.
Run it locally
Use a hosted C17 compiler in a separate lab folder. The command assumes a driver named cc; substitute gcc, clang or zig cc as appropriate. C does not currently run in Bhylu’s browser playground. Apache, PHP and MySQL are not needed for these C programs.
cc -std=c17 -Wall -Wextra -Wpedantic -Werror enums-typedef.c -o lessonOn Windows, use -o lesson.exe and run .\lesson.exe in PowerShell. On Unix-like systems run ./lesson. Math-library linking differs by toolchain; GCC on many Unix systems needs -lm after the source.
Download the complete C source. File-writing labs must run in an empty private directory, away from existing reports.
Example
#include <stdio.h>
enum ReviewState { PENDING, REVIEWED, REJECTED };
typedef struct { int id; enum ReviewState state; } Reading;
int main(void) {
Reading reading = {.id = 9, .state = REVIEWED};
const char *label = reading.state == REVIEWED ? "reviewed" : "pending";
printf("Reading %d: %s\n", reading.id, label);
return 0;
}
Expected result
Reading 9: reviewed
The enum names express intent without scattering numeric codes. Reading is an alias for the structure type, simplifying its declarations. A complete application would map every valid state and reject unknown values rather than collapsing all non-reviewed states into pending. Persistent file formats should define their own stable codes instead of writing an implementation-dependent enum representation.
For language and library rules, consult the WG14 C working group and its public C11 committee draft, which describes the core facilities used here; C17 incorporates corrections. Check your compiler and runtime documentation for implementation details.