this post was submitted on 28 May 2025
752 points (100.0% liked)

Programmer Humor

24788 readers
535 users here now

Welcome to Programmer Humor!

This is a place where you can post jokes, memes, humor, etc. related to programming!

For sharing awful code theres also Programming Horror.

Rules

founded 2 years ago
MODERATORS
 

Also, do y'all call main() in the if block or do you just put the code you want to run in the if block?

(page 3) 50 comments
sorted by: hot top controversial new old
[–] [email protected] 3 points 1 month ago* (last edited 1 month ago) (8 children)

Can someone explain to me how to compile a C library with "main" and a program with main? How does executing a program actually work? It has an executable flag, but what actually happens in the OS when it encounters a file with an executable file? How does it know to execute "main"? Is it possible to have a library that can be called and also executed like a program?

Anti Commercial-AI license

[–] [email protected] 2 points 1 month ago

I haven't done much low level stuff, but I think the 'main' function is something the compiler uses to establish an entry point for the compiled binary. The name 'main' would not exist in the compiled binary at all, but the function itself would still exist. Executable formats aren't all the same, so they'll have different ways of determining where this entry point function is expected to be. You can 'run' a binary library file by invoking a function contained therein, which is how DLL files work.

load more comments (7 replies)
[–] [email protected] 3 points 1 month ago (1 children)

Shouldn't the third panel just be empty?

[–] [email protected] 2 points 1 month ago

It’s fine like this

[–] [email protected] 2 points 1 month ago

Its called runpy.run_script

[–] [email protected] 1 points 1 month ago

main.py or did you not read the manual?

[–] [email protected] 1 points 1 month ago

Depends on how lazy I am at the moment.

load more comments
view more: ‹ prev next ›