Practice ยท 3 of 4
Tentative Definitions
C allows a file-scope int x; (a "tentative definition") that merges with
a later real definition. Implement a tiny analyzer:
``c
/* events: 'T' tentative (int x;), 'D' real definition (int x = 0;),
'E' extern declaration. n events across TUs. */
int is_valid_program(const char *events);
``
Valid iff there is exactly one 'D' and zero or more 'T's before or after it, or
zero 'D' and at least one 'E' somewhere (definition lives in another TU).
Any other combination is invalid (return 0; valid returns 1). NULL or empty
returns 0.
Difficulty: intermediate
Press Submit to check your solution.
Back to lesson: Practice: Duration & Linkage Gym