Re:What happens before main() is executed in C and why is it...
by ddtaylor on Friday May 04, 2018 @07:42PM
(#16999321)
Is it strange that C++ is able to do this but C itself cannot? Sometimes I hear the argument that "C is lower level" and their is the idiom that "C++ is C but better" (not that I believe these are true)
[ Parent
| on HN ]
Re:What happens before main() is executed in C and why is it...
by Retric on Friday May 04, 2018 @07:48PM
(#16999343)
It's somewhat misleading when they say the C++ code runs before main. What's going on is after the same initialization steps the first code of your program is executed.
C and C++ have different syntax for what that code is, but it's pure semantics as far as the computer is concerned and C++ gives you zero extra power.
Re:What happens before main() is executed in C and why is it...
by kbumsik on Friday May 04, 2018 @07:53PM
(#16999368)
It is certainly possible to do this with C by editing a startup code. In embedded system, a source code of startup is provided and exposed by manufacturer's SDK so it is quite straightforward to do this.
Besides that, I can't see much difference between doing something before main() and just putting some code on the very top of main().