r/linux • • May 24 '20

Analyzing The Simplest C++ Program

https://oneraynyday.github.io/dev/2020/05/03/Analyzing-The-Simplest-C++-Program/
235 Upvotes

21 comments sorted by

View all comments

4

u/[deleted] May 24 '20

Idk what the cpp program there is but it's not the simplest. The simplest program is



21

u/OneRaynyDay May 24 '20

You actually raise a really good point! Do you need to define the main function? According to the c++ standards, you do need to define the main function. Now whether that main function is implicitly defined for you if you're missing one is up to the toolchain (clang, g++, msvc), but the final binary will be identical to one that is written with int main() {}. Please refer to: https://en.cppreference.com/w/cpp/language/main_function.

3

u/JonnyRobbie May 24 '20 edited May 24 '20

Unfortunately I don't know where I've read it, but there was a nice blogpost detailing "Smallest program that will crash", which went to a nice detail of the corner cases of C language.

EDIT: http://llbit.se/?p=1744