News for hackers. Stuff that matters.
Re:What happens before main() is executed in C and why is it... by jononor on Friday May 04, 2018 @01:22PM (#16996321)
The linker script is what runs the global constructors in C++. Nothing preventing using a custom linker script in C to call some `premain()` function.
Re:What happens before main() is executed in C and why is it... by baruch on Friday May 04, 2018 @01:28PM (#16996381)
At least in gcc you can use constructor attribute to run code before main. I've seen this used to initialize modules and create a dependency tree of modules to initialize before main even starts.
Re:What happens before main() is executed in C and why is it... by housel on Friday May 04, 2018 @02:48PM (#16997187)
To be picky, the linker script lays out a sequence of calls to the global constructors so that the C runtime startup knows where to find and execute them.