You are reading a single comment by @Kolban and its replies. Click here to read the full conversation.
  • My guess would the the compilation flag "-DNO_ASSERT" is the key component. If we look in "jsutils.h" we find that this flag is used to control the implementation of "assert()" statements in the source code.

    An assert() statement is a debugging/coders tool that checks the truthiness of an expression at runtime. We want to "assert that some condition is true at this point". The asserts are added by coders who have concern that some condition that they expect to be true at this point actually is ... and if not ... usually stop here and alert someone. One shouldn't use assert() statements to trap "expected" issues ... for example ... if a filename is expected to be passed to a routine and it is found to be NULL, that would most likely be checked via exception and return code ... however if we presume that an internally calculated number will never be zero ... because we "think" the logic should not allow that ... then coding:

    assert(x !=0);

    is a good programmers statement to catch errors.

    In a production/released solution, usage of "assert" statements should no longer be present. When an end user runs a program, it is meaningless to them to see:

    assert at line 1234 for file xyz.c: x!=0

    Instead we would hope they would see a nice message or a dialog and gracefull degredation of the application. Because asserts should only used during development time, they should be "removed" for a production release. However, because we don't want to go through source code and remove asserts when they might still be useful in the future, what we want is a build time flag that determines whether or not the assert() statements are included in the compiled code.

    Espruino seems to use the C definition "NO_ASSERT" to remove them. During compile, if NO_ASSERT is set, then assert() statements are "no-oped". Since an assert statement will be an "injection" of code into the source, switching off assertions ... by setting NO_ASSERT which is set when RELEASE=1 prevents the assert() statements from being inserted. No assert() statements ... smaller compiled code ... smaller resulting image size.

About

Avatar for Kolban @Kolban started