Can i create a function inside of void setup() to recall in loop() function


No. You do not create functions within functions.

You can create a function, and then call it both from setup() and loop() if you so wish.


You can create functions within a function if the particular c compiler supports it - gcc, the compiler used by arduino, does. But not all c compilers support that.

Whether you can create a function within a function that recalls loop() depends on your meaning of "recall".


Defining a function within a function is not supported in C or C++. If it were supported in a way consistent with the rest of the language, the inner function would be local to the outer function, just as local variables are, so not callable or even visible from outside the outer function.

Your loop() function (or any other function) could, however, call the setup() function as long as you want to execute setup() again in its entirety. That means that any initialization you perform in setup() would be repeated each time you call it.


You have asked two questions here. In the title, can you define a function inside of setup(): Yes.

But that is the "scope" of where it can be used.

In Loop() it won't exist, ("xxx undefined in this scope") so the answer to what you ask in the text is No.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.