Skip to content

OIL 41, chapter Functions: host code returns its results - #126

Merged
theAndreas merged 2 commits into
mainfrom
oil-41-functions-results
Nov 17, 2026
Merged

theAndreas merged 2 commits into
mainfrom
oil-41-functions-results

Conversation

@theAndreas

Copy link
Copy Markdown
Owner

Nothing changes for a sketch or for whoever uses the simulator or the control program. The library is untouched, and every example has the same flash and RAM as on main.

The third pull request of the review of the chapter Functions in OIL item 41, for FN-8 and FN-15 of the coding style, as decided on 2026-11-17: a result is returned, not written into a parameter, and a parameter that must exist is a reference, not a pointer. The host code wrote some 40 results through pointers, mostly a bool beside the value it found.

  • What a function finds or reads it now returns; where it also says whether it found anything, the two come back in a small struct of their own, as std::optional is C++17 and the host code is built as gnu++11.
  • What the simulator's hosts receive they return, and the caller appends it.
  • A buffer that grows over many calls, an index the caller moves on, and the picture DocuPictures draws on are references.
  • One function keeps references for what it sets up: the start of a simulator run sets up the two objects the tick reaches through a plain function pointer, rather than returning copies; the reason is at its declaration.

Checked:

  • make check passes: lint, clang-tidy, every host and AVR test, coverage at 100 % of lines, branches and conditions; the tests of the WebSocket, the hosts, the ports, the link and the commands call the new signatures.
  • The control program's window builds; it was not clicked through, and its Windows half was not compiled, as there is no MinGW in the dev container.
  • Not run on hardware; the library does not change.

No function of the simulator, the control program or DocuPictures writes
its result through a pointer any more. What one finds or reads it
returns, with whether it did in a small struct of its own where both are
needed; what the hosts receive they return, and the caller appends. A
buffer that grows over many calls, an index the caller moves on, and an
object a function draws on are references. SimulatorRun::SetUp() keeps
its two, as it sets up the objects the tick reaches.

The library and its sizes do not change.
@theAndreas
theAndreas merged commit 08c7acd into main Nov 17, 2026
12 checks passed
@theAndreas
theAndreas deleted the oil-41-functions-results branch November 17, 2026 15:03
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants