Skip to main content
8 events
when toggle format what by license comment
Apr 10, 2022 at 9:38 comment added dandavis the missing define is not missing from your sketch, it's missing from the lib's cpp file, which is it's own thing. one neat trick i've used is to put all the lib code in an H file instead of the cpp file. The result is basically that that H-file code just pasted in-place in the sketch, which means prior defines are available to it. I don't know if there's downsides to it, but it works as I expect...
Apr 9, 2022 at 19:11 answer added JRobert timeline score: -1
Apr 9, 2022 at 15:37 answer added Juraj timeline score: 1
Apr 8, 2022 at 23:15 comment added Majenko If I were doing what you describe I'd be using a class with a constructor whose code is in the header file and thus gets recompiled for each translation unit (i.e. within the sketch for example). That constructor would be called with macros you can override from the sketch since the constructor forms part of the same TU as the sketch.
Apr 8, 2022 at 23:13 comment added Majenko When you compile a .c or .cpp file it gathers all the header files contents together and literally does string replacement on the #includes and then the #defines. Then compiles that one big resultant file. That's a translation unit. In general for every cpp or c file you have one translation unit. It's a self contained thing which can't be modified by anything outside. The only exception is in Arduino if you have multiple .ino files in a sketch they get concatenated together into one gigantic translation unit.
Apr 8, 2022 at 23:03 comment added user47164 Can you explain translation units? I've heard of them, but they seem very nebulous to me.
Apr 8, 2022 at 22:58 comment added Majenko From my reading of the source code for that library I can't see that it can work as described. The library code (cpp files) are different translation units to the sketch where the #define would be located.
Apr 8, 2022 at 22:49 history asked user47164 CC BY-SA 4.0