This commit is contained in:
Miloslav Ciz 2022-04-01 16:06:14 +02:00
parent a75cf4faf0
commit 095dda21dd
2 changed files with 135 additions and 11 deletions

27
c.md
View file

@ -50,23 +50,28 @@ TODO
## Basics
A simple program in C looks like e.g. like this:
This is a quick overview, for a more in depth tutorial see [C tutorial](c_tutorial.md).
A simple program in C that writes "welcome to C" looks like this:
```
TODO
#include <stdio.h> // standard I/O library
int main(void)
{
// this is the main program
puts("welcome to C");
return 0; // end with success
}
```
You can simply paste this code into a file which you name e.g. `program.c`, then you can compile the program from command line like this:
You can quickly compile the program from command line like this:
`gcc -o program program.c`
`gcc -o my_program my_program.c`
You can replace `gcc` with other compilers (e.g. `clang`, `tcc`, `g++` etc.), they mostly understand the same flags. Some important flags you may want to add:
- `-O3`: optimize for program speed, greatly speeds up your program (you can also use less aggressive `-O2` and `-O1`)
- `-Os`: optimize for smaller program size
- `-g`: include debug info, you want this so that debuggers can point to your source code
- `-std=c99`: use the C99 standard
Then if you run the program from command line (`./program` on Unix like systems) you should see the message.
## Cheatsheet