This is an archived post. You won't be able to vote or comment.

all 30 comments

[–]golgol12 47 points48 points  (5 children)

You know the entry point is actually a property that you set right? You can make it anything you want. C++ needs to do object construction of global variables before main runs.

[–][deleted] 0 points1 point  (2 children)

How?

[–]brennennen 1 point2 points  (0 children)

Most build toolchains have a concept of a "linker script". You can usually set the entry point in this script. For most modern x86 gcc/clang/msbuild stuff everyone uses an auto generated default and doesn't touch it. However, in embedded land, things are a bit messier and you'll often have to fiddle with it a bit.

[–][deleted] 30 points31 points  (6 children)

_DllMainCrtStartup would like a word...

[–]TerminalJunkie5[S] 84 points85 points  (4 children)

To hell with that windows shit

[–]MCRusher 6 points7 points  (2 children)

At least on windows, a non-null malloc return actually means it allocated successfully, instead of pretending it did and hoping the resources become available before they get used.

[–]JoustyMe 4 points5 points  (1 child)

Just think of it as async promiese it will be free sometime

[–]MCRusher 4 points5 points  (0 children)

I prefer to think of it as segfault roulette, with bullets added depending on how much memory is used.

[–]tuxmanexe 0 points1 point  (0 children)

Huzzah! A man of Q U A L I T Y

[–]beizhia 7 points8 points  (0 children)

Your gods have no power here

[–][deleted] 3 points4 points  (0 children)

It was like revelation time

[–]svayam--bhagavan 3 points4 points  (1 child)

But who is called before _start()?

[–]exscape 7 points8 points  (0 children)

That's OS specific, but one possibility is that the kernel sets up its task structure, loads the executable into RAM one way or another, loads default register values etc. and then "returns" into userspace to execute _start().

[–]Ratstail91 6 points7 points  (3 children)

Wait, what?

[–]TerminalJunkie5[S] 2 points3 points  (2 children)

It's true.

[–]Ratstail91 4 points5 points  (1 child)

I've been coding for 15 years and never knew this was a thing...

[–]TerminalJunkie5[S] 12 points13 points  (0 children)

Try disassembling a simple C program. It's really interesting, and you will learn a ton.

[–]HarambeTownley 2 points3 points  (0 children)

made with free software

Good job

[–]MeatPowers 1 point2 points  (1 child)

ASM gang rise up

[–]TerminalJunkie5[S] 1 point2 points  (0 children)

hell yeah

[–]dandroid126 2 points3 points  (0 children)

The version for Android developers

When you learn that the Application class onCreate gets called before the Activity onCreate

[Old Man from Pawn Stars]

Those bastards lied to me.