This is the classic lexical vs dynamic scoping. Dynamic scoping works great until it doesn't.

Don’t use C then? It sounds like you want JavaScript, Python, or Lisp.

Once again, the caller of the API does not declare any variables so there is no dynamic scoping.