Why Function Pointers are Awesome

Поділитися
Вставка
  • Опубліковано 29 лис 2024

КОМЕНТАРІ • 32

  • @HansBezemer
    @HansBezemer 3 місяці тому +3

    I couldn't live without function pointers! Agreed, nowadays I use a language (Forth) which makes it much easier to use function pointers, but I wrote my Forth compiler by basically using three tables - one of which with function pointers using something resembling your second technique.

  • @victormanuel8767
    @victormanuel8767 3 місяці тому +2

    This coming off the heels of me just learning to use function pointers is super helpful. It contextualizes use cases really well, and i wish there was a discussion of their applications for the use cases at the end of the video.

    • @beningoembedded
      @beningoembedded  3 місяці тому

      Thanks for the suggestion. Maybe something I'll do in the future in a different video. The idea of this one was to be a super short talk that discusses the technique. I agree more indepth looks would be helpful!

  • @LomasSubedi
    @LomasSubedi 2 роки тому +2

    Thank you Jacob, your presence in here and on different blog article is helping so much to learn and understand.

  • @paulchamberlain7942
    @paulchamberlain7942 26 днів тому

    Just to contribute an actual use case. I use an object that ties together the essential elements of running a simulation. The function pointer parameters allow different functions for different platforms. For example, the millisecond elapsed function is different for arduino and windows:
    FrameTimer(uint16_t frame_int, uint16_t aux_int, U32_CALLBACK p_time_fn,
    VOID_CALLBACK p_frame_fn, VOID_CALLBACK p_render_fn, VOID_CALLBACK p_aux_fn)
    An example of usage would be:
    pTimer = new FrameTimer(1000 / MAX_FPS, 500, millis, Update, Draw, Debug);
    FrameTimer is a rubbish name but has proven to be a very useful object for running simulations.

  • @CuriousCyclist
    @CuriousCyclist Рік тому

    Really good video! Thanks for taking the time to make it.

  • @waynerifish
    @waynerifish 2 роки тому +2

    Regarding "Make sure function pointers are NOT stored in RAM"... when I register a callback function, isn't that callback function pointer stored in RAM somewhere (e.g., UART0_ISR->function), even if it's done in pre-compiled or auto-generated code?

  • @JayDee-b5u
    @JayDee-b5u 3 місяці тому +1

    I think you misspoke at ~ 6:19, "You don't want these (function pointers) in FLASH...". I think you meant, "You don't want these (function pointers) in RAM...".

  • @grimvian
    @grimvian 11 місяців тому

    The use cases gives me inspiration to enhance my C code, so a big thank you from me.

  • @btoven66
    @btoven66 2 роки тому

    Great to see you again!!!

    • @beningoembedded
      @beningoembedded  2 роки тому +1

      Thanks Peter! I'm planning to post a lot more this year so stay tuned!

  • @deltakid0
    @deltakid0 2 роки тому +1

    Could you please explain how the ATTiny85 bootloader works? It's a very basic MCU.
    Thank you.

  • @NeedBetterLoginName
    @NeedBetterLoginName 4 місяці тому +1

    What a great little vid! Thanks.

  • @boudewijndijkstra82
    @boudewijndijkstra82 Рік тому +1

    Another problem is that calculating the maximum stack usage becomes non-trivial. For each function pointer invocation it has to be clear which functions can potentially be called.

    • @beningoembedded
      @beningoembedded  Рік тому +1

      Absolutely! Thanks for the comment and observation!

    • @anon_y_mousse
      @anon_y_mousse 3 місяці тому

      It gets harder still when using C and VLA's. Imagine even trying to guess when the size comes from the user too.

  • @shahfenil08
    @shahfenil08 2 роки тому +1

    Interestingly, I violated the rule that said it should be constant and my code was crashing because it was pointing to the 0x0. As I was debugging the issue, I found out another bug index out range. So one bug exposed another nasty bug. Note that, before implementing function pointer other bug was still there but I couldn't find out because my program haven't crashed or going into hard fault. :D

  • @Bob-zg2zf
    @Bob-zg2zf Рік тому +1

    I just bought your book today.❤

    • @beningoembedded
      @beningoembedded  Рік тому +1

      Excellent! I hope you enjoy it!

    • @Bob-zg2zf
      @Bob-zg2zf Рік тому

      @@beningoembedded I ordered it but I have not received it. I hope I will indeed enjoy it as much as I enjoyed your videos. The thing is, my expertise level is not that advanced. I am afraid I won't understand all or most of your book's contents. But I like your video contents and style and background.

    • @Bob-zg2zf
      @Bob-zg2zf Рік тому

      @@beningoembedded Do you mind if I ask you a simple question? I have read your article, where you mentioned that we are supposed to "write rock-solid embedded software". But I can only design and solder an STM32 board with HCD1080, using someone's Keil project code that I downloaded from the Internet. So, how do I write my own entire project/code? How do I improve myself from using others' code to "write my own rock-solid embedded software"? The architecture seems so difficult to master to write from scratch or modify here and there....

  • @colinmaharaj
    @colinmaharaj Місяць тому

    I haven't tried but i know putty used this, but I haven't figured out how to use this yet in my apps

  • @ralflici986
    @ralflici986 4 місяці тому

    Very interesting talk, thank you!

  • @timon1027
    @timon1027 2 місяці тому

    Thank you for your information😊

  • @bahtiyar.bayram
    @bahtiyar.bayram 2 роки тому +1

    Great content!

  • @hsaidinsan6345
    @hsaidinsan6345 2 роки тому +2

    Do they affect the real time performance?

    • @beningoembedded
      @beningoembedded  2 роки тому +2

      Function pointers will not have a negative impact on the real-time performance. They can improve readability, scalability, and reusability though. They can also decrease maintenance too.
      If you were to look at what a function call really is, it's just a pointer to the functions code anyway!

  • @fifaham
    @fifaham 4 місяці тому +2

    Function pointers are evil? I have always used them and I never had any problem with them, unless you have a bad memory or stack overflow or damaged memory section then this will never happen, assuming there is an active WDT monitoring those special cases. I have always recommended to use an auxiliary MCU in case the first had damaged memory then the second takes over - in case of medical or security applications.

    • @beningoembedded
      @beningoembedded  4 місяці тому +1

      Exactly. Unless this, unless that. There are companies that deem them evil and that they should be avoided at all costs. I love and use them all the time. If you know what you're doing, you can avoid all those "unlesses"!
      Thanks for the comment!

  • @ThePing98
    @ThePing98 2 роки тому

    Great video thank u