From f3498a0c07fef4fb6d0b0f06ff048bc029b31ce6 Mon Sep 17 00:00:00 2001 From: Ciprian Dorin Craciun Date: Wed, 28 Nov 2012 08:05:36 +0200 Subject: [PATCH] User overridable `setup`, `loop` and `main` through `__attribute__((weak))` Following the same pattern as in the case of `serialEvent`, I've done the following: * provide an empty implementation of the `setup` and `loop` functions; * mark all three functions (`setup`, `loop` and `main`) as `__attribute__ ((weak))` so that the user is able to override them with customized versions; See issue https://github.com/arduino/Arduino/issues/1138 --- hardware/arduino/cores/arduino/main.cpp | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/hardware/arduino/cores/arduino/main.cpp b/hardware/arduino/cores/arduino/main.cpp index 3d4e079d2a0..56cc0c52d14 100644 --- a/hardware/arduino/cores/arduino/main.cpp +++ b/hardware/arduino/cores/arduino/main.cpp @@ -1,5 +1,9 @@ #include +extern "C" void setup(void) __attribute__((weak)); +extern "C" void loop(void) __attribute__((weak)); + +__attribute__((weak)) int main(void) { init(); @@ -8,13 +12,12 @@ int main(void) USBDevice.attach(); #endif - setup(); + if (setup) setup(); for (;;) { - loop(); + if (loop) loop(); if (serialEventRun) serialEventRun(); } return 0; } -