#define

Поделиться
HTML-код
  • Опубликовано: 2 окт 2024

Комментарии • 5

  • @Volker-Dirr
    @Volker-Dirr 6 месяцев назад

    I didn't tried it yet, but in the arduino languarge reference in chapter "#define" they wrote "This can have some unwanted side effects though, if for example, a constant name that had been #defined is included in some other constant or variable name. In that case the text would be replaced by the #defined number (or text)."

  • @whathuh6965
    @whathuh6965 Месяц назад +1

    I'm unclear on which use case is better because both #define and const are good at performance. I would argue that #define is faster due to the pre-processed result, but I don't know if that makes the usage better. I guess const has more flexibility and clarity than #define but again I don't know if that makes it better.

  • @robertbauer6723
    @robertbauer6723 5 месяцев назад

    I thought that using symbolic constants versus constant variables would affect the size of the compiled output. So I did a test comparing #define and "const int." The compiled sketch in both cases used the same number of bytes. So I am left with only what you said; using symbolic constants can lead to difficulties when debugging. That is very good to know. Thank you.

    • @playduino
      @playduino  5 месяцев назад

      Thank you for the feedback! I think the compiler optimizes both versions to the same result all the time.

  • @Volker-Dirr
    @Volker-Dirr 6 месяцев назад

    I am also not 100% sure about 1:47. I think technically it is not unclear. (But I agree that probably not all coders know, so it is difficult to read and I also prefer to see the type.) From the arduino reference about integers "By default, an integer constant is treated as an int with the attendant limitations in values. To specify an integer constant with another data type, follow it with 'u', 'U', 'l', 'L', 'ul' or 'UL' ".