]> granicus.if.org Git - esp-idf/commit
newlib: change definition of assert for release builds
authorIvan Grokhotkov <ivan@espressif.com>
Mon, 16 Jan 2017 16:49:38 +0000 (00:49 +0800)
committerIvan Grokhotkov <ivan@espressif.com>
Mon, 16 Jan 2017 16:49:38 +0000 (00:49 +0800)
commitc47cc6348947cfd1aa6a8aa87e0764c1f07630c6
tree9cdf8c0f60d82af2fdc02e4810fb8d2ddaf4c82c
parent075446318df651216be42966e721c30d822b48e2
newlib: change definition of assert for release builds

One common pattern of using assert function looks as follows:
    int ret = do_foo();
    assert(ret == 0);   // which reads as: “do_foo should never fail here, by design”
The problem with such code is that if ‘assert’ is removed by the preprocessor in release build,
variable ret is no longer used, and the compiler issues a warning about this.
Changing assert definition in the way done here make the variable used, from language syntax perspective.
Semantically, the variable is still unused at run time (as sizeof can be evaluated at compile time), so the compiler
can optimize things away if possible.
components/newlib/include/assert.h
components/nvs_flash/src/nvs_pagemanager.cpp