linux-sysprog · beginner · ~15 min
Know the one correct type for a handler flag.
A flag shared between a signal handler and the main code must be volatile sig_atomic_t: sig_atomic_t guarantees atomic access and volatile stops the compiler caching it. Validate the declared type.
Implement int flag_type_ok(const char *type) that returns 1 only if type is exactly the correct handler-flag type.
type: a C type spelled as a string.1 only for "volatile sig_atomic_t"; 0 for anything else (e.g. "int", "volatile int").
flag_type_ok("volatile sig_atomic_t") -> 1
flag_type_ok("int") -> 0
flag_type_ok("volatile int") -> 0
type: a C type spelled as a string.
1 only for "volatile sig_atomic_t", else 0.
Exact string match required.
#include <string.h>
int flag_type_ok(const char *type) {
/* TODO */
return 0;
}
Solve this exercise in the browser editor — compile and run against the test harness, no setup required.