Search code examples
theory

Unread variables in a program with only if/else statements


Given a program with only if/else statements is it then possible to decide which variables that occur but never read?


Solution

  • Yes. Given a program with only if/else statements [assuming no branches backwards and loops], there is a finite number of paths in the program.

    You can check all of them, check which conditions must be met in order to get to each path, and find contradictions [un accessable paths], and this way to find which variables are never used.

    This can be implemented as a simpler version of Hoare logic, which is pretty simple to automatize, without loops. [with loops it is of course impossible to automatize it]