You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Our modified convention of this approach will state that:
for every _init function, a _free function should be called at the end of the struct's lifetime for future proofing and clean memory management.
_init and _free functions should of type void (this raises the question of "what happens if an error happens in the function" and this is answered in the next rule)
_init and _free function bodies should be immune to run-time errors and any error that is of no fault of the caller. Preconditions should be defined in the function docs and if the caller of the function does not follow those preconditions, then it is of no fault of the function itself, and it is not the function's responsibility to return an error code, hence why we allow ourselves to set the function type to void. This also means that malloc cannot be used in _init because malloc is prone to memory full run-time error, for example.
The text was updated successfully, but these errors were encountered:
Using this as a note to self to do this
We follow MbedTLS' OOP approach in C.
Our modified convention of this approach will state that:
_init
function, a_free
function should be called at the end of the struct's lifetime for future proofing and clean memory management._init
and_free
functions should of typevoid
(this raises the question of "what happens if an error happens in the function" and this is answered in the next rule)_init
and_free
function bodies should be immune to run-time errors and any error that is of no fault of the caller. Preconditions should be defined in the function docs and if the caller of the function does not follow those preconditions, then it is of no fault of the function itself, and it is not the function's responsibility to return an error code, hence why we allow ourselves to set the function type tovoid
. This also means thatmalloc
cannot be used in_init
becausemalloc
is prone to memory full run-time error, for example.The text was updated successfully, but these errors were encountered: