embxx icon indicating copy to clipboard operation
embxx copied to clipboard

Throw used in StaticQueue

Open akowalew opened this issue 7 years ago • 2 comments

In the README you have said, that this library is not using exceptions. When I tried to compile simple program, that uses your EventLoop (which has inside a StaticQueue object) with explicity disabled exceptions (-fno-exceptions) I got an error, because there is throw used (StaticQueue.h:242):

ConstReference at(std::size_t index) const
{
    if (index >= size()) {
        throw std::out_of_range(std::string("Index is out of range"));
    }
    return (*this)[index];
}

Maybe do you just replace this statement with GASSERT(index < size()); and then leave operator[] without any assertion?

By the way, great work - awesome library!

akowalew avatar Jan 18 '18 10:01 akowalew

That's an arguable point. I introduced "at" member function just for interface completeness in case someone would want to replace usage of say boost::circular_buffer with my StaticQueue (or vice versa) and get the same result. The embedded application should never use at() member function and I think my EventLoop doesn't use it. It seems your compiler tries to compile a function that is not used. The problem with using GASSERT macro is that it exists only in Debug mode compilation and disappears when compiled in Release mode. The at() member function is supposed to check index validity and report error in any compilation mode. I'd recommend cloning my code to your own repositories and removing the at() member function altogether to get your code compiled.

I haven't touched this project for quite a while, my hands are full with CommsChampion and related projects at this moment, and I don't known when I'll be able to look at this one again and test the latest gcc / clang compilers.

arobenko avatar Jan 18 '18 23:01 arobenko

Thank you. I did it like you said, by removing at function from StaticQueue.

Project seems to work very well on current compilers (my toolchain is arm-none-eabi-gcc 7.2.0) with small fixes in other modules.

akowalew avatar Jan 18 '18 23:01 akowalew