Hello everyone, I am currently following Andrew McPherson's course on YouTube and learning C++. I checked the code and realized there is no main() function in the code. I thought all C++ codes had to have a main() am I wrong or is it hidden somewhere in the Bela context?
No main() function?
Alleycat I thought all C++ codes had to have a main() am I wrong [...] ?
FWIW, you can technically write a program whose entry point is different from main()
. That's achieved passing --entry=myEntryPoint
to the linker (see https://gcc.gnu.org/onlinedocs/gcc/Link-Options.html).
Alleycat is it hidden somewhere in the Bela context?
It's hidden in the Bela backend. This ugly couple of lines https://github.com/BelaPlatform/Bela/blob/master/Makefile.linkbela#L42-L43 checks whether there a function called main
has been defined in the user-defined cpp files. If it's not, then it links in this file which provides a default main()
function. This initialises the audio backend and directly or indirectly calls the user-defined functions setup()
, render()
and cleanup()
.
giuliomoro ok, I did not know about the entry point. Thanks for the explanation and linking the source code!