Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/jterrazz/awesome-42
🍉 The best for your 42 journey.
https://github.com/jterrazz/awesome-42
List: awesome-42
42 42school c learning norminette testing tips tools
Last synced: 3 months ago
JSON representation
🍉 The best for your 42 journey.
- Host: GitHub
- URL: https://github.com/jterrazz/awesome-42
- Owner: jterrazz
- Created: 2019-05-24T20:13:09.000Z (over 5 years ago)
- Default Branch: master
- Last Pushed: 2019-10-22T00:23:51.000Z (about 5 years ago)
- Last Synced: 2024-05-20T02:47:41.099Z (6 months ago)
- Topics: 42, 42school, c, learning, norminette, testing, tips, tools
- Homepage:
- Size: 2.84 MB
- Stars: 31
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
- awesome-42 - Awesome 42 - Correction tips, code snippets and good practices. (Student projects / Awesome lists)
README
# Awesome 42
> A collection of the best ressources for your 42 school journey. Please feel free to fork it / contribute to it.
### Index
- [Ressources](#ressources)
- [Subjects](#subjects)
- [Automated tests](#automated-tests)
- [How to make a perfect correction / project](#how-to-make-a-perfect-correction-/-project)
- [Useful code snippets](#useful-code-snippets)
- [Good practices](#good-practices)## Ressources
### Subjects
- [Binary-Hackers](https://github.com/Binary-Hackers/42_Subjects)### Automated tests
- [42 File Checker](https://github.com/jgigault/42FileChecker) ❤️: Fillit / Libft / LibftASM / Get_next_line / Ft_ls / Ft_printf / Minishell
- [@jtoty](https://github.com/jtoty/Libftest): Libft
- [@mguillau42](https://github.com/mguillau42/unit_test_nm_otool) : Nm-otool### Automated code formating
I created an uncrustify config file for the [42 norm](./_norm/uncrustify.cfg). Uncrustify allows you to format automatically your `.c` and `,h` files. It's not complete yet, feel free to contribute to it 🙏.
### Tricks
- [Simulate linux efficiently on MacOS](https://github.com/jterrazz/docker-devstation)
## A complete correction basics
*On the newly cloned project*
- `cat -e auteur` must show the login followed by a `\n` (print as `$` with `cat -e`).
- `norminette | grep 'Error'` should print nothing.
- `cat */*.c | grep "By: "` should print the student login (it can print for the mail).### The makefile
- should have the basic rules: `all` , `$(NAME)`, `clean`, `fclean` and `re`.
- should clean the entire project with `fclean` .
- should compile with `-Werror -Wextra -Wall`.
- should not have any `*`.
- should compile only modified files using `.o` temporary object files.### No cheating
- `nm -u ` should print the allowed functions for the subject. Take into account only the functions starting with one _.
- In case other functions are used for bonuses, it must be justified (for example, `printf` for laziness is not allowed).### No crash
- `malloc` return should be secure. Don't forget to check for libft return too (ft_strnew()` for example`).
- `malloc` should not leak. Each `malloc` must match with a `free`, see why [here](https://stackoverflow.com/questions/32966125/is-it-really-important-to-free-allocated-memory-if-the-programs-just-about-to-e).
- However, no need to free the entire program when you use exit() on an error.
- You can use `valgrind --leak-check=full <./ft_exec>` to search leaks. In case the program outputs data, you can redirect valgrind output with `--log-fd=9 9>>val.log`.
- Check for double `free`.
- `open` , `read` return should be secure (returns -1 for errors). When opening or reading, you should test with folders and not allowed files (`chmod 000`).
- `open` must be followed by `close`.
- `mmap` return must be secure.```
ptr = mmap(0, buf.st_size, PROT_READ | PROT_WRITE, MAP_PRIVATE, fd, 0)) == MAP_FAILEDCheck for leaks
```### Other
- When implementing existing methods, check their prototype matches exactly.
- When implementing existing commands, check it diplays the exact same return. Use `diff <(./ft_x) <(x)`
- Check if globals are allowed. Use `nm <./ft_x>` to display them.
- Check your overflows.
- When the program expects arguments, check with empty strings.
- For executables, create a usage message.## Useful code snippets
### Save flags
```c
typedef enum e_flag {
FLAG_N = 1 << 0, // 0b00000001
FLAG_R = 1 << 1, // 0b00000010
FLAG_G = 1 << 2, // 0b00000100
} t_flag;// Use uint_64t for more than 8 flags
int flags = 0; // flags = 0b00000000// Activate the flag N
flags |= FLAG_N // flags = 0b00000001// Compare it with
if (flags & FLAG_N) // TRUE
...
```### Round x to a multiple of y
```c
int x = (x + (y-1)) & ~(y-1);
```## Good practices
### Project file structure
```bash
/project
/inc # Put all your includes here (from libs + src)
/libs # Put you libft + other already made projects
/src
Makefile # Will call the makefile of libs
auteur
```### Code
- Use `static` on local functions and `const` for constants variables.
- Describe exported functions using comments
- Print errors in the FD error
- Don't use `if (ptr) free(ptr)`, it does it for you.
- Stop thinking the norm is bad, 25 lines per function will make you code better and generic functions
- Use real variable / function names 😢
- You can use `makefile -j18` for compiling using multithread.