Modern C++: C++ Patterns to Make Embedded Programming More Productive - Steve Bush - CppCon 2022

แชร์
ฝัง
  • เผยแพร่เมื่อ 29 พ.ย. 2024

ความคิดเห็น • 35

  • @matthieulabas
    @matthieulabas ปีที่แล้ว +18

    5:28 Declarative GPIO
    16:15 Compiler-driven lookup table generation
    23:21 Address-like structures
    31:00 Lean stream-based I/O
    40:55 Using heap in embedded applications (arena allocators)
    50:23 Unlock std::chrono
    54:56 Unlock std::random

  • @maxtruxa
    @maxtruxa ปีที่แล้ว +10

    `std::format` and by extension `std::print`/`std::println` are actually extensible just as well as iostreams (take a look at `std::formatter`), even allowing for custom format options which was not possible with iostreams.

  • @yyyy-uv3po
    @yyyy-uv3po ปีที่แล้ว +7

    Really liked the readable numeric structures.
    Thank you for your time.

  • @yezariaelll
    @yezariaelll ปีที่แล้ว +5

    Nice talk and great tips, thanks!

  • @brunizzl
    @brunizzl ปีที่แล้ว +6

    The custom shift operator overloads shown at 39:13 can actually also be done for std::iostream. These are normal operator overloads and thus are discovered by the overload resolution if they are declared in the same namespace as the (second) argument or as the caller.

    • @gustavojmalano
      @gustavojmalano ปีที่แล้ว +1

      That is clear, but he got rid of std::iostreams because they are too expensive (talking about binary size) for an embedded device.

  • @eotcoldhymns2930
    @eotcoldhymns2930 ปีที่แล้ว

    why have not used enum class? why not put & in to const std::array coeff?

  • @RadimPolasek
    @RadimPolasek ปีที่แล้ว +3

    thank you for such great hints

  • @patricklittle1002
    @patricklittle1002 3 หลายเดือนก่อน

    How does the LUT table work when the coefficients are pulled from the factory calibration data stored in micro?

  • @hstrauss2214
    @hstrauss2214 ปีที่แล้ว +1

    I think that the overload/redefinition of std::chrono::highresolution_clock::now() presented at 52:40 is not allowed by the standard and maybe not even possible.

  • @danielmilyutin9914
    @danielmilyutin9914 ปีที่แล้ว +1

    So title changed. And I thought I missed talk "Modern C++ to Impress Your Embedded Dev Friends" :-)

  • @verycucumber
    @verycucumber ปีที่แล้ว +3

    I think it is not optimal to configure pins one by one in a loop, it is basically writes few bits (via read, bitwise-OR, write) into the same MMIO register again and again. What I do is I calculate a bunch of registers values (during compilation) and write those constants into MMIO registers. If it takes 10 registers to configure GPIO, it takes 10 writes then. No loops, no bitwise-OR.

    • @lukasz_kostka
      @lukasz_kostka ปีที่แล้ว

      I'm curious how you did that. Can you share some code ?

    • @wojtekburzynski654
      @wojtekburzynski654 ปีที่แล้ว +6

      But do you need this to be optimal? Correct me if I'm wrong, but you configure IO pins is once in a lifetime of a program, so i doesn't matter if you save couple of writes.

    • @HelderParracho
      @HelderParracho ปีที่แล้ว +3

      @@wojtekburzynski654 it might be important to put the IO pins into a safe and known state as fast as possible, depending on your application and/or hardware.

    • @szymoniak75
      @szymoniak75 11 หลายเดือนก่อน

      @@HelderParracho so as always... use proper tool for a job

  • @szymoniak75
    @szymoniak75 11 หลายเดือนก่อน

    19:53 are these actually are going to be evaluated at compile time? since std::pow is not constexpr?

    • @stefanalecu9532
      @stefanalecu9532 4 หลายเดือนก่อน

      It will be constexpr in C++26, it's not hard to write your own

  • @jasoncole7711
    @jasoncole7711 ปีที่แล้ว

    Very useful talk, especially for those with a C background, but yes we know what Proctor & Gamble do....... skip the first 4 minutes

  • @eriktheheroful
    @eriktheheroful ปีที่แล้ว

    Great talk!

  • @hstrauss2214
    @hstrauss2214 ปีที่แล้ว

    The code presented at about 28:30 centainly does not work at all. There are useless lines like "index == 1;" and a wrong mix up of 'index' and 'count' for 'result.mData' and 'text'. Finally, to parse a hex string to bytes, two characters need to be combined to a single byte. Can not see this happinging anywhere in the code.

  • @vi_volga
    @vi_volga ปีที่แล้ว

    Thank you!

  • @christophclear1438
    @christophclear1438 ปีที่แล้ว +3

    19:30 std::pow is _not_ `constexpr`...

    • @destiny_02
      @destiny_02 ปีที่แล้ว +1

      I believe it is in C++23

    • @peterlauro9222
      @peterlauro9222 ปีที่แล้ว +2

      @@destiny_02believenes has nothing to do with reality. (have a look at c++ standard section 28.7.1 Header synopsis). on g++ compiler it's accepted because the internal implementation of std::pow is based on internal __builtin_pow functions. Just take a simple code: constexpr auto i = std::pow(2.0, 3.5); on g++ is going to compile, on clang++ and msvc compilers, the compilation fails. The approach presented in the talk is not supported by the c++ standard.

    • @nextlifeonearth
      @nextlifeonearth ปีที่แล้ว +1

      @@peterlauro9222 IMO pretty much all functions in cmath should be constexpr and if they aren't, it's an oversight.

    • @hstrauss2214
      @hstrauss2214 ปีที่แล้ว +1

      @@nextlifeonearth It is not really an oversight. Overall, it is just not as easy as it seems. The math functions can have side effects, like setting the errno variable for certain input values. A constexpr function can not set errno.

  • @la_ki
    @la_ki ปีที่แล้ว

    First time I heard for resistor divider.

  • @Dziaji
    @Dziaji ปีที่แล้ว +17

    This talk is more like "c++ basics that might impress a first year CS student"

    • @peterfistin8584
      @peterfistin8584 ปีที่แล้ว +23

      True, but there are hundreds of companies that still use the most basic approaches from the 90'. The presenter shows here a much modern way - that's why it is important to have those sessions.

    • @mapron1
      @mapron1 ปีที่แล้ว +21

      Embedded programmers (at least all I knew) usually use C++ as C with classes/destructors. So anything beyond that will be an impression for them.

    • @theondono
      @theondono ปีที่แล้ว +3

      @@peterfistin8584 habitual reminder that this wasn’t because of backwardness, but because up until ARM became the de facto standard, most C++ compilers had no guarantees about supporting features past C89.

    • @drnoob13
      @drnoob13 ปีที่แล้ว +5

      Many embedded engineers write C++ code as C with a C++ compiler. Introducing neat modern C++ practices for embedded programming bring net benefits to every one.

    • @ch33rfulness
      @ch33rfulness ปีที่แล้ว +1

      @@mapron1 True, I’m one of them 🤣
      Been involved in a dozen of companies, in safety critical applications…the core functionally was always C, and only some fancy libraries were C++, but as you’ve said, we’ve been using the C++ in a very simple way. It makes sense, if you think about it. I think that C allows us to understand easily the propagation of a signal from hardware to the topmost application layer.