Quantcast
Channel: Raspberry Pi Forums
Viewing all articles
Browse latest Browse all 7333

SDK • [Solved] Pre-main and Post-main functions

$
0
0
GCC 12.2.0 supports pre-main and post-main functions which work for native Pi builds -

Code:

#include <stdio.h>void __attribute__ ((constructor)) pre_main  (void) { printf("pre_main\n");  }void __attribute__ ((destructor))  post_main (void) { printf("post_main\n"); }int main(void) {    printf("  In main\n");}

Code:

pi@Pi4B:~ $ gcc main.cpi@Pi4B:~ $ ./a.outpre_main  In mainpost_main
For Pico SDK builds using the ARM GCC 12.2.1 compiler it calls 'pre-main' before 'main' but never reaches 'post_main'. In the '.dis' file I can see code for 'pre_main' but nothing at all for 'post_main'.

How do I make having an automatically invoked 'post_main' work ?

Statistics: Posted by hippy — Mon Jul 28, 2025 10:45 am — Replies 2 — Views 66



Viewing all articles
Browse latest Browse all 7333

Trending Articles