Skip to content

Commit

Permalink
Pade out hello_world
Browse files Browse the repository at this point in the history
  • Loading branch information
robertdfrench committed Jul 25, 2024
1 parent 8e30fae commit 7ffd450
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 3 deletions.
12 changes: 10 additions & 2 deletions code/hello_world.c
Original file line number Diff line number Diff line change
@@ -1,6 +1,14 @@
// This program is used to demonstrate the fact that binaries have
// metadata stored in them that tells the linker which dynamic libraries
// they need in order to run.
#include <stdio.h>

int main(int argc, char** argv) {
printf("Hello from %s!\n", argv[0]);
return 0;
// We have to make printf do something non-trivial here, or the
// compiler will simplify it to "puts" instead. That would just
// make th example more confusing. So we have it print something
// that will always be available: the name of the running
// program.
printf("Hello from %s!\n", argv[0]);
return 0;
}
10 changes: 9 additions & 1 deletion dynamic_linking.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,15 @@ program is executed, functions and variables can be imported from
is called, and is handled automatically for you by a tool called
[`ld.so(8)`][kerrisk]. This process is called *dynamic linking*.

As an example, take a look at [`hello_world.c`](code/hello_world.c).
As an example, take a look at [`hello_world.c`](code/hello_world.c):

```c
int main(int argc, char** argv) {
printf("Hello from %s!\n", argv[0]);
return 0;
}
```
This is a simple "Hello World"-style program that calls `printf` to
print the name of the running program. Because printf itself is not
defined in your program, you'll need to import a suitable definition
Expand Down

0 comments on commit 7ffd450

Please sign in to comment.