Skip to content
This repository was archived by the owner on May 7, 2025. It is now read-only.

Commit c2c5962

Browse files
authored
Merge pull request #30 from Lind-Project/29-addimprove-hello-world-and-tutorial-guide
Add examples page for code samples and sample outputs
2 parents b494685 + 2242fe3 commit c2c5962

4 files changed

Lines changed: 75 additions & 0 deletions

File tree

docs/images/hello_screenshot1.png

42.1 KB
Loading

docs/images/hello_screenshot2.png

69.6 KB
Loading

docs/use/examples.md

Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
# Examples of Compiling and Running
2+
3+
## Hello, World!
4+
To begin, a simple "Hello World" file can be created. In this case, as follows:
5+
```c
6+
#include <stdio.h>
7+
8+
int main() {
9+
printf("Hello, World!\n");
10+
return 0;
11+
}
12+
13+
```
14+
First, it can be compiled and run as usual with native gcc:
15+
```bash
16+
gcc hello.c -o hello
17+
./hello
18+
```
19+
20+
Then under lind, where it should produce the same output:
21+
```
22+
./lindtool.sh cptest hello
23+
./lindtool.sh run hello
24+
```
25+
<!-- A sample output is shown below:
26+
<a href="../../images/hello_screenshot1.png" target="_blank">
27+
![Hello World Screenshot](../images/hello_screenshot1.png)
28+
</a> -->
29+
30+
## Example with Header file included
31+
32+
Header files can be included in the same way. Below is a simplified example:
33+
#### `print_it.h`:
34+
```
35+
#ifndef PRINT_IT_H
36+
#define PRINT_IT_H
37+
38+
#include <stdio.h>
39+
#include <time.h>
40+
41+
static inline void print_it(const char *message) {
42+
time_t now = time(NULL);
43+
struct tm *t = localtime(&now);char timestamp[20];
44+
strftime(timestamp, sizeof(timestamp), "%Y-%m-%dT%H:%M:%S", t);
45+
printf("%s %s\n", timestamp, message);
46+
}
47+
48+
#endif
49+
```
50+
#### `helloworld.c`:
51+
```c
52+
#include "print_it.h"
53+
54+
int main() {
55+
print_it("Hello, World!");
56+
return 0;
57+
}
58+
59+
```
60+
Again, it can be compiled and run as usual with native gcc:
61+
```bash
62+
gcc helloworld.c -o helloworld
63+
./helloworld
64+
```
65+
66+
Then under lind, where it should produce the same output:
67+
```
68+
./lindtool.sh cptest helloworld
69+
./lindtool.sh run helloworld
70+
```
71+
<!-- A sample output is shown below:
72+
<a href="../../images/hello_screenshot2.png" target="_blank">
73+
![Hello World With Headers Screenshot](../images/hello_screenshot2.png)
74+
</a> -->

mkdocs.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ nav:
99
- Compiling programs: use/compile-programs.md
1010
- Running programs: use/run-programs.md
1111
- Debugging programs: use/debug-programs.md
12+
- Examples: use/examples.md
1213
- Internal Documentation:
1314
- libc: internal/libc.md
1415
- Wasmtime: internal/wasmtime.md

0 commit comments

Comments
 (0)