Giter Club home page Giter Club logo

crc_cpp's People

Contributors

ashleyroll avatar stephanka avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar

Forkers

stephanka iulove

crc_cpp's Issues

function in class `crc` are not constexpr

First of all, I went to your talk (virtually) at cppcon and I really enjoyed it and this library is really great. I have many legacy IOT message formats that use really "unique" polynomials and starting values, so often it is a real pain to use other libraries. Yours was very easy to specialize for our CRCs.

The issue I am running into is that I can't use the crc class in a constant expression. This seems to be a simple oversight, since to fix it I just mark all the functions in that class constexpr. I can also see how it was missed because all my code worked until this morning! I have no idea what changed, I just renamed some files, but now it won't compile unless I make those functions contexpr.

Here is a minimal example godbolt:

#include <https://raw.githubusercontent.com/AshleyRoll/crc_cpp/main/include/crc_cpp.h>
#include <span>

constexpr bool check_message(std::span<const uint8_t> data, const uint8_t expected) {
    // CRC for upper half is header + first 4 sats and is in byte 14
    crc_cpp::crc8 crc;
    for(const auto b : data) {
        crc.update(b);
    }
    return expected == crc.final();
}

compiler output:

<source>: In function 'constexpr bool check_message(std::span<const unsigned char>, uint8_t)':
<source>:10:33: error: call to non-'constexpr' function 'crc_cpp::impl::crc<TAlgorithm, TABLE_SIZE>::accumulator_type crc_cpp::impl::crc<TAlgorithm, TABLE_SIZE>::final() [with TAlgorithm = crc_cpp::impl::crc_algorithm<unsigned char, 7, 0, 0, false>; crc_cpp::table_size TABLE_SIZE = crc_cpp::table_size::small; crc_cpp::impl::crc<TAlgorithm, TABLE_SIZE>::accumulator_type = unsigned char]'
https://raw.githubusercontent.com/AshleyRoll/crc_cpp/main/include/crc_cpp.h:410:44: note: 'crc_cpp::impl::crc<TAlgorithm, TABLE_SIZE>::accumulator_type crc_cpp::impl::crc<TAlgorithm, TABLE_SIZE>::final() [with TAlgorithm = crc_cpp::impl::crc_algorithm<unsigned char, 7, 0, 0, false>; crc_cpp::table_size TABLE_SIZE = crc_cpp::table_size::small; crc_cpp::impl::crc<TAlgorithm, TABLE_SIZE>::accumulator_type = unsigned char]' declared here
Compiler returned: 1

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.