Say I'm working on a library^1 to which I want to add support for SD.h^2 but knowing for a fact that many microcotrollers don't support SD.h (therefore they result in compilation errors [eg. Attiny85]) I don't want to just #include <SD.h> (or even #ifndef __SD_H__ then #include <SD.h>) in Mylibrary.h and make it totally unusable for some microcontrollers. So I was wondering, is it considered ok to just add the functionality like...
// Mylibrary.h
#ifdef SD_H
// Save functionality for those including SD.h to their sketch.ino
void Mylibrary::save(String filename){
SD.open(filename, FILE_WRITE)
// ...
}
#endif
...without ever including the SD.h in Mylibrary.h and hence force the user whenever he\she wants to use some SD functionallity, to just include SD.h in his\her sketch.ino? +(it sound exhausting to do something like this for every MCU, as an alternative way)
[1] (in my case this library)
[2] (in my case something related to this)
PS. The reason I'm asking is because I don't remember seeing it anywhere being used that way and I'm slightly confused as to if this is the right or wrong thing to do so
.hfor the sake of better MACRO optimization – Giorgos Xou Nov 07 '23 at 15:59