Arduino F(): what does it actually do

前端 未结 2 753
無奈伤痛
無奈伤痛 2020-12-31 00:27

I have asked a similar question before, but I realize that I can\'t make heads or tails of the macrology and templateness. I\'m a C (rather than C++) programmer.

Wha

2条回答
  •  清歌不尽
    2020-12-31 00:59

    BTW. For th ESP32 library, both of these functions are defined in the following files:

    # PSTR :  ../Arduino/hardware/espressif/esp32/cores/esp32/pgmspace.h
    # F    :  ../Arduino/hardware/espressif/esp32/cores/esp32/WString.h
    

    and the F(x):

    // an abstract class used as a means to proide a unique pointer type
    // but really has no body
    class __FlashStringHelper;
    #define F(string_literal) (reinterpret_cast(PSTR(string_literal)))
    ...
    

    Also for ESP32, PSTR(x) is not needed and is just x: #define PSTR(s) (s).

提交回复
热议问题