espsoftwareserial icon indicating copy to clipboard operation
espsoftwareserial copied to clipboard

add "weak" attribute to function isValidGPIO , isValidRxGPIO , isValidTxGPIO

Open fanfanlatulipe26 opened this issue 3 years ago • 2 comments

This request is a followup of #240 (valid pins for RX/TX, strapping pins ...) Please could you add "weak" attribute to the functions:

bool isValidGPIOpin(int8_t pin);
bool isValidRxGPIOpin(int8_t pin);
bool isValidTxGPIOpin(int8_t pin);

bool isValidGPIOpin(int8_t pin)  __attribute__ ((weak)); 
bool isValidRxGPIOpin(int8_t pin) __attribute__ ((weak));
bool isValidTxGPIOpin(int8_t pin) __attribute__ ((weak));

In this way the user can replace them and still use the standard library. No need for "patched" local version of the library. No compatibility issues. Regards

fanfanlatulipe26 avatar Aug 18 '22 10:08 fanfanlatulipe26

Is there any particular reason you prefer C-style weak linkage over C++ polymorphism?

dok-net avatar Oct 02 '22 12:10 dok-net

Sorry, I am not a C++ expert (nor even a C one !) ... Just trying to play a bit with microcontrolers... I just found that it was very easy to use my own isValidGPIOpin if the function is declared with the weak attribute in the library. Just need to write my own function and the linker will gives it priority. I don't know how it can be done in the C++ polymorphism context.

fanfanlatulipe26 avatar Oct 02 '22 19:10 fanfanlatulipe26

Keeping #261, closing this one.

dok-net avatar Dec 14 '22 21:12 dok-net