3 ms·
I've written code like this in C to create library functions that will be linked in to other projects, but where there is no 'main' function in the C file. Do
by xjwm 4y ago
I've written code like this in C to create library functions that will be linked in to other projects, but where there is no 'main' function in the C file. Do people use C++ the same way, or is it best practice to include 'main?'
- MathMonkeyMan 4y agoIt's the same as in C. The observation here is that variables with static storage duration can be initialized by running user code before main() begins.
- xjwm 4y agoOh! Thank you. That makes much more sense now.
- colejohnson66 4y agoIt’s also the same in .NET. If your Main() function references types that have a static constructor, the constructors could run before Main(). It’s a surprising thing when one first discovers it, but it makes a lot of sense.