Should I use 'retained' with 'extern's?

My code is split across multiple .cpp files, and I’ve just introduced some retained variables to use the Backup RAM, which is working really well.

However, I have a syntax question - as these are global variables, defined in one C file and used in another, should i use the retained keyword on the extern definitions?


retained bool setupDone = false;
void setup() {
  // Interactive setup stuff here...
  setupDone = true;


retained extern setupDone; // <--- Is 'retained' neccessary/recommended?
int publishStatus(String command) {
  if(setupDone) {
    // Publish stuff for cloud interface


Retained is only needed on the variable declaration - extern references don’t need it.

1 Like