mirror of
https://github.com/stnolting/neorv32.git
synced 2025-04-23 21:57:33 -04:00
[sw/example] demo_newlib: add destructor test
This commit is contained in:
parent
e3e4eb73cf
commit
4b34a9690b
1 changed files with 14 additions and 3 deletions
|
@ -26,6 +26,16 @@
|
|||
/**@}*/
|
||||
|
||||
|
||||
/**********************************************************************//**
|
||||
* @name Print main's return code using a destructor
|
||||
**************************************************************************/
|
||||
void __attribute__((destructor)) main_destructor_test(void) {
|
||||
|
||||
int32_t main_ret = (int32_t)neorv32_cpu_csr_read(CSR_MSCRATCH);
|
||||
neorv32_uart0_printf("\nDestructor: main terminated with return/exit code %i.\n", main_ret);
|
||||
}
|
||||
|
||||
|
||||
/**********************************************************************//**
|
||||
* @name Max heap size (from linker script's "__neorv32_heap_size")
|
||||
**************************************************************************/
|
||||
|
@ -111,10 +121,11 @@ int main() {
|
|||
// NOTE: exit is highly over-sized as it also includes clean-up functions (destructors), which
|
||||
// are not required for bare-metal or RTOS applications... better use the simple 'return' or even better
|
||||
// make sure main never returns. Anyway, let's check if 'exit' works.
|
||||
neorv32_uart0_printf("terminating via <exit> ");
|
||||
exit(0);
|
||||
int exit_code = 7;
|
||||
neorv32_uart0_printf("<exit> terminating by exit(%i)...\n", exit_code);
|
||||
exit(exit_code);
|
||||
|
||||
// should never be reached
|
||||
neorv32_uart0_printf("failed!n");
|
||||
neorv32_uart0_printf("exit failed!\n");
|
||||
return 0;
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue