samples, tests, boards: Switch main return type from void to int

As both C and C++ standards require applications running under an OS to
return 'int', adapt that for Zephyr to align with those standard. This also
eliminates errors when building with clang when not using -ffreestanding,
and reduces the need for compiler flags to silence warnings for both clang
and gcc.

Most of these changes were automated using coccinelle with the following
script:

@@
@@
- void
+ int
main(...) {
	...
-	return;
+	return 0;
	...
}

Approximately 40 files had to be edited by hand as coccinelle was unable to
fix them.

Signed-off-by: Keith Packard <keithp@keithp.com>
This commit is contained in:
Keith Packard 2023-02-07 21:00:59 -08:00 committed by Stephanos Ioannidis
commit 0b90fd5adf
447 changed files with 1617 additions and 1231 deletions

View file

@ -15,7 +15,7 @@
static const struct gpio_dt_spec led =
GPIO_DT_SPEC_GET(DT_ALIAS(led0), gpios);
void main(void)
int main(void)
{
bool led_is_on = true;
@ -37,4 +37,5 @@ void main(void)
}
led_is_on = !led_is_on;
}
return 0;
}

View file

@ -11,14 +11,14 @@
#include <zephyr/sys/printk.h>
#include <zephyr/sys/__assert.h>
void main(void)
int main(void)
{
const struct device *const dev =
DEVICE_DT_GET(DT_CHOSEN(zephyr_console));
if (!device_is_ready(dev)) {
printk("Console device not ready");
return;
return 0;
}
#if CONFIG_PM_DEVICE
@ -51,4 +51,5 @@ void main(void)
}
#endif
return 0;
}

View file

@ -108,7 +108,7 @@ static void bt_ready(int err)
printk("Beacon stopped\n");
}
void main(void)
int main(void)
{
int err;
@ -148,4 +148,5 @@ void main(void)
printk("Shutdown\n");
pm_state_force(0u, &(struct pm_state_info){PM_STATE_SOFT_OFF, 0, 0});
return 0;
}