Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 34 additions & 0 deletions Segfault.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
# Segfaults. We hate them...

## Definiton:
In computing, a segmentation fault (often shortened to segfault) or access violation is a failure condition raised by hardware with memory protection, notifying an operating system (OS) that the software has attempted to access a restricted area of memory (a memory access violation). On standard x86 computers, this is a form of general protection fault. The operating system kernel will, in response, usually perform some corrective action, generally passing the fault on to the offending process by sending the process a signal. Processes can in some cases install a custom signal handler, allowing them to recover on their own, but otherwise the OS default signal handler is used, generally causing abnormal termination of the process (a program crash), and sometimes a core dump.
([Source](https://en.wikipedia.org/wiki/Segmentation_fault)).

## Note:
This definition was purely for educational purposes, you can stop here if you don't hate Segfaults :nerd_face:. I am writing this with the intention of expressing my hate for this error, that made my hair go white.

## Why I hate it :rage::
1. It can be caused from basically everything if you are not paying attention when working with dinamically allocated memory. You didn't free? Segfault. You did free? Maybe Segfault. You allocated bad? Segfault. You allocated in the first place? Your chances of Segfaults are at 90%.
1. It can take time to repair...when a C or C++ program segfaults, the terminal typically spits out just a few unhelpful words: Segmentation fault (core dumped). There is no context, no line number, and no immediate clue as to what went wrong. You are entirely on your own to figure out where the crash happened. Just you and Valgrind...
1. Because segfaults are intimately tied to exactly how a program is laid out in the computer's physical RAM, attempting to debug them can inadvertently change their behavior.
If you add a simple print statement to try and track down where the code is failing, you alter the size of the compiled program and shift its memory layout. Suddenly, the segfault might move to a completely different part of the program, or it might vanish entirely—only to return the moment you remove your debugging code.

## How do I solve Segfaults?
Well...there could be light after dark after all, your heroes are:
- **Valgrind**:
- Run with:
``bash
valgrind <your_object_file>
``
- **GDB**:
1. First, you have to compile your code with:
```bash
gcc ... -g ...
```
2. After that, you have to run it with:
```bash
gdb <object_file>
```

### So, to end it on a funny note:
![Segfault Meme](https://i.programmerhumor.io/2025/07/39f9ce344066838d5f3d50da0abb33e99369f9f71afa6320a1d34ca6d8b016c5.png)
Binary file added demo
Binary file not shown.
2 changes: 1 addition & 1 deletion dynamic-linking.ro.md
Original file line number Diff line number Diff line change
Expand Up @@ -186,4 +186,4 @@ num_items: 1

Variabila de mediu `LD_LIBRARY_PATH` pentru loader este echivalentul opțiunii `-L` în comanda de linkare: precizează directoarele în care să fie căutate biblioteci pentru a fi încărcate, respectiv linkate.
Folosirea variabilei de mediu `LD_LIBRARY_PATH` este recomandată pentru teste.
Pentru o folosire robustă, există alte mijloace de precizare a căilor de căutare a bibliotecilor partajate, documentate în [pagina de manual a loaderului / linkerului dinamic](https://man7.org/linux/man-pages/man8/ld.so.8.html#DESCRIPTION).
Pentru o folosire robustă, există alte mijloace de precizare a căilor de căutare a bibliotecilor partajate, documentate în (pagina de manual a loaderului / linkerului dinamic)[https://man7.org/linux/man-pages/man8/ld.so.8.html#DESCRIPTION].
7 changes: 7 additions & 0 deletions gnumake/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,10 @@
# to the end of the line!

# Start writing below this line...
.PHONY: clean

clean:
rm example

example: example.c
gcc -o example example.c
29 changes: 29 additions & 0 deletions gnumake/custom/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
CC = gcc
CFLAGS = -Wall -Wextra
GDB_FLAGS = -g

# rule that ignores files in the directory that have "all" title
# or "clean" title so that we can run these recipes safely
.PHONY: all clean

# rule that executes all the rules that we give to her
all: greeting parts

ifeq ($(CC), gcc)
$(info Using GCC compiler...)
else
$(warning Warning! C program needs to be executed with gcc)
endif

# rule that uses a conditional to make clear that the program will compile
# with gcc and that runs the greeting.c file
greeting: greeting.c
$(CC) $(CFLAGS) $(GDB_FLAGS) $^ -o $@

# the clean rule removes all the object files made so that we won't
# have binary files that may corrupt our running and also executable files
clean:
rm -f *.o greeting parts

# we put it here so when we run "make" simple it will take the all rule
include parts_makefile
3 changes: 3 additions & 0 deletions gnumake/custom/parts_makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
#We use another file for this rule so that we can see how can we scatter rules across different files
parts: header.h part1.c part2.c
$(CC) $(CFLAGS) $(GDB_FLAGS) $^ -o parts
84 changes: 84 additions & 0 deletions helloworld.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
# Helloworld Programs

![Hello, World!](https://github.com/SerbaC6/workshop-markdown-fork/blob/helloworld/helloworld.png?raw=true)

We list below Helloworld programs for different programming languages, i.e. programs that print "Hello, World!". The
specified compiler or interpreter is required for each programming languages.

The table below summarizes the programs:

| *Language* | *Language (Spec) Site* | *Section* | *Build / Run Toolchain* | *Debian / Ubuntu Packages* |
| :----- | :--------------------: | :-------: | :---------------------: | :------------------------: |
| C | [The Standard - C](https://www.iso-9899.info/wiki/The_Standard) | [C]() | GCC |``build-essential`` |
| C++ | [The Standard - C++](https://isocpp.org/std/the-standard) | [C++]() | GCC / G++ |``build-essential, g++`` |
| Dlang | [D Programming Language: Hpme](https://dlang.org/) | [Dlang]() | GCC / GDC |``build-essential, gdc`` |
| Go | [The Go Programming Language](https://go.dev/) | [Go]() | Go |``golang`` |
| Rust | [Rust Programming Language](https://www.rust-lang.org/) | [Rust]() | Rust(Crate) |``rustlang`` |
|Java | [Java Programming Language](https://docs.oracle.com/javase/8/docs/technotes/guides/language/) | [Java]() | JDK | ``openjdk-17-jdk`` |
|x86_64 assembly | [x86 and amd64 instruction reference](https://www.felixcloutier.com/x86/) | [x86_64]() | Assembly GCC / GAS | ``build-essential`` |
|ARM64 assembly | [Arm A64 Instruction Set Architecture](https://developer.arm.com/documentation/ddi0596/latest/) | [ARM64 Assembly]() | GCC / GAS (AArch64) | ``build-essential``|
|Bash | [Bash Reference Manual](https://www.gnu.org/s/bash/manual/bash.html) | [Bash]() | Bash | ``bash``|
|Python| [Welcome to Python.org](https://www.python.org/)| [Python]() | Python | ``python``|
|Ruby | [Ruby Programming Language](https://www.ruby-lang.org/en/) | [Ruby]() | Ruby |``ruby``|
|PHP | [PHP: Hypertext Preprocessor](https://www.php.net/)| [PHP]() | PHP | ``php`` |
|Perl| [The Perl Programming Language](https://www.perl.org/) | [Perl]() | Perl | ``perl``|
|Lua | [The Programming Language Lua](https://www.lua.org/) | [Lua]() | Lua | ``lua``|



# C
```C
#include <stdio.h>
int main(void)
{
puts("Hello, World!");
return 0;

}
```

Build with:
```bash
gcc -Wall -o helloworld helloworld.c
```
Run with:
```bash
./helloworld
```

# C++
```C++
#include <iostream>
int main()
{
std::cout << "Hello, World!" << std::endl;
return 0;
}
```

Build with:
```bash
g++ -Wall -o helloworld helloworld.cpp
```

Run with:
```bash
./helloworld
```

# Dlang
```dlang
import std.stdio;
void main()
{
writeln("Hello, World!");
}
```
Build with:
```bash
gdc -Wall -o helloworld helloworld.cpp
```
Run with:
```bash
./helloworld
```