Skip to content

Commit 0b90fd5

Browse files
keith-packardstephanosio
authored andcommitted
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>
1 parent fc076f5 commit 0b90fd5

File tree

447 files changed

+1617
-1231
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

447 files changed

+1617
-1231
lines changed

boards/arm/mps2_an521/empty_cpu0/src/main.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,12 @@
88

99
extern void wakeup_cpu1(void);
1010

11-
void main(void)
11+
int main(void)
1212
{
1313
/* Simply wake-up the remote core */
1414
wakeup_cpu1();
1515

1616
while (1) {
1717
}
18+
return 0;
1819
}

kernel/init.c

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -332,11 +332,7 @@ static void bg_thread_main(void *unused1, void *unused2, void *unused3)
332332
z_mem_manage_boot_finish();
333333
#endif /* CONFIG_MMU */
334334

335-
#ifdef CONFIG_CPP_MAIN
336335
extern int main(void);
337-
#else
338-
extern void main(void);
339-
#endif
340336

341337
(void)main();
342338

samples/application_development/code_relocation_nocopy/src/main.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ void disable_mpu_rasr_xn(void)
4242
extern void function_in_ext_flash(void);
4343
extern void function_in_sram(void);
4444

45-
void main(void)
45+
int main(void)
4646
{
4747
#ifdef CONFIG_ARM_MPU
4848
disable_mpu_rasr_xn();
@@ -54,4 +54,5 @@ void main(void)
5454
function_in_sram();
5555

5656
printk("Hello World! %s\n", CONFIG_BOARD);
57+
return 0;
5758
}

samples/application_development/external_lib/src/main.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,9 @@
1212

1313
#include <mylib.h>
1414

15-
void main(void)
15+
int main(void)
1616
{
1717
printf("Hello World!\n");
1818
mylib_hello_world();
19+
return 0;
1920
}

samples/application_development/out_of_tree_board/src/main.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,8 @@
77
#include <zephyr/kernel.h>
88
#include <zephyr/sys/printk.h>
99

10-
void main(void)
10+
int main(void)
1111
{
1212
printk("Hello World! %s\n", CONFIG_ARCH);
13+
return 0;
1314
}

samples/application_development/out_of_tree_driver/src/main.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ static void user_entry(void *p1, void *p2, void *p3)
1515
hello_world_print(dev);
1616
}
1717

18-
void main(void)
18+
int main(void)
1919
{
2020
printk("Hello World from the app!\n");
2121

@@ -27,4 +27,5 @@ void main(void)
2727

2828
k_object_access_grant(dev, k_current_get());
2929
k_thread_user_mode_enter(user_entry, NULL, NULL, NULL);
30+
return 0;
3031
}

samples/application_development/sysbuild/with_mcuboot/src/main.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,9 @@
77
#include <zephyr/kernel.h>
88
#include <zephyr/linker/linker-defs.h>
99

10-
void main(void)
10+
int main(void)
1111
{
1212
printk("Address of sample %p\n", (void *)__rom_region_start);
1313
printk("Hello sysbuild with mcuboot! %s\n", CONFIG_BOARD);
14+
return 0;
1415
}

samples/arch/mpu/mpu_test/src/main.c

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -139,15 +139,16 @@ static int cmd_mtest(const struct shell *shell, size_t argc, char *argv[])
139139
return 0;
140140
}
141141

142-
void main(void)
142+
int main(void)
143143
{
144144
#if defined(CONFIG_SOC_FLASH_MCUX) || defined(CONFIG_SOC_FLASH_LPC) || \
145145
defined(CONFIG_SOC_FLASH_STM32)
146146
if (!device_is_ready(flash_dev)) {
147147
printk("Flash device not ready\n");
148-
return;
148+
return 0;
149149
}
150150
#endif
151+
return 0;
151152
}
152153

153154
SHELL_STATIC_SUBCMD_SET_CREATE(sub_mpu,

samples/arch/smp/pi/src/main.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ void test_thread(void *arg1, void *arg2, void *arg3)
7777
atomic_dec(counter);
7878
}
7979

80-
void main(void)
80+
int main(void)
8181
{
8282
uint32_t start_time, stop_time, cycles_spent, nanoseconds_spent;
8383
int i;
@@ -112,4 +112,5 @@ void main(void)
112112

113113
printk("All %d threads executed by %d cores in %d msec\n", THREADS_NUM,
114114
CORES_NUM, nanoseconds_spent / 1000 / 1000);
115+
return 0;
115116
}

samples/arch/smp/pktqueue/src/main.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -133,7 +133,7 @@ void queue_thread(void *arg1, void *arg2, void *arg3)
133133
k_mutex_unlock(&fetch_queue_mtx);
134134
}
135135

136-
void main(void)
136+
int main(void)
137137
{
138138
uint32_t start_time, stop_time, cycles_spent, nanoseconds_spent;
139139

@@ -201,4 +201,5 @@ void main(void)
201201
}
202202

203203
k_sleep(K_MSEC(10));
204+
return 0;
204205
}

0 commit comments

Comments
 (0)