diff --git a/src/c_examples/module0_setup.c b/src/c_examples/module0_setup.c new file mode 100644 index 0000000..6a16dd0 --- /dev/null +++ b/src/c_examples/module0_setup.c @@ -0,0 +1,416 @@ +// ============================================ +// Modul 0: Entwicklungsumgebung einrichten +// Ein Leitfaden für VS Code, C/C++ und Git +// ============================================ + +/* + * Dieses Modul ist KEIN C-Code, sondern eine Anleitung! + * Speichere dies als .md oder lies es als Kommentar. + */ + +/* +================================================================================ +🛠️ MODUL 0: ENTWICKLUNGSUMGEBUNG EINRICHTEN +================================================================================ + +Dieses Modul zeigt, wie du eine professionelle C/C++ Entwicklungsumgebung +mit Visual Studio Code einrichtest und mit Git/Gitea arbeitest. + +================================================================================ +📥 SCHITT 1: VISUAL STUDIO CODE INSTALLIEREN +================================================================================ + +Linux (Ubuntu/Debian): +----------------------- +curl https://packages.microsoft.com/keys/microsoft.asc | gpg --dearmor > packages.microsoft.gpg +sudo install -D -o root -g root -m 644 packages.microsoft.gpg /etc/apt/keyrings/packages.microsoft.gpg +sudo sh -c 'echo "deb [arch=amd64,arm64,armhf signed-by=/etc/apt/keyrings/packages.microsoft.gpg] https://packages.microsoft.com/repos/code stable main" > /etc/apt/sources.list.d/vscode.list' +rm -f packages.microsoft.gpg +sudo apt update +sudo apt install code + +Windows: +-------- +1. https://code.visualstudio.com/download +2. Installer herunterladen und ausführen +3. "Add to PATH" aktivieren! + +macOS: +------ +brew install --cask visual-studio-code + +================================================================================ +🔧 SCHRITT 2: C/C++ EXTENSIONS INSTALLIEREN +================================================================================ + +In VS Code (Ctrl+Shift+X für Extensions): + +1. **C/C++** (Microsoft) + - ID: ms-vscode.cpptools + - IntelliSense, Debugging, Code-Navigation + +2. **C/C++ Extension Pack** (Microsoft) + - ID: ms-vscode.cpptools-extension-pack + - CMake Tools, CMake, Makefile Tools + +3. **GitLens** (GitKraken) + - ID: eamodio.gitlens + - Erweiterte Git-Integration + +4. **Error Lens** (Alexander) + - ID: usernamehw.errorlens + - Fehler direkt im Code anzeigen + +5. **Better Comments** (Aaron Bond) + - ID: aaron-bond.better-comments + - Farbige Kommentare (TODO, FIXME, etc.) + +Tastenkürzel für Extensions: Ctrl+Shift+X + +================================================================================ +⚙️ SCHRITT 3: C/C++ COMPILER INSTALLIEREN +================================================================================ + +Linux (GCC): +------------ +sudo apt update +sudo apt install build-essential gdb + +# Prüfen: +gcc --version # Sollte 11.x oder höher zeigen +g++ --version # Sollte 11.x oder höher zeigen + +Windows (MinGW-w64): +-------------------- +Option A: MSYS2 (Empfohlen) +1. https://www.msys2.org/ herunterladen +2. Installieren und Terminal öffnen +3. pacman -S mingw-w64-x86_64-gcc +4. C:\msys64\mingw64\bin zu PATH hinzufügen + +Option B: WinLibs (Einfacher) +1. https://winlibs.com/ +2. GCC-Version herunterladen +3. Entpacken und bin/ zu PATH hinzufügen + +macOS (Clang): +-------------- +# Xcode Command Line Tools +xcode-select --install + +# Oder GCC via Homebrew +brew install gcc + +================================================================================ +📁 SCHRITT 4: PROJEKTSTRUKTUR ERSTELLEN +================================================================================ + +Empfohlene Struktur für C-Projekte: +------------------------------------ +my-project/ +├── .vscode/ # VS Code Konfiguration +│ ├── tasks.json # Build-Tasks +│ ├── launch.json # Debugging +│ └── settings.json # Editor-Einstellungen +├── src/ # Quellcode +│ ├── main.c +│ └── utils.c +├── include/ # Header-Dateien +│ └── utils.h +├── tests/ # Unit-Tests +├── build/ # Kompilierte Dateien (gitignore!) +├── docs/ # Dokumentation +├── Makefile # Build-Anweisungen +├── README.md # Projektbeschreibung +└── .gitignore # Git-Ausschlüsse + +VS Code Konfiguration (.vscode/tasks.json): +------------------------------------------- +{ + "version": "2.0.0", + "tasks": [ + { + "label": "Build C Program", + "type": "shell", + "command": "gcc", + "args": [ + "-g", + "-Wall", + "-Wextra", + "-o", + "${workspaceFolder}/build/${fileBasenameNoExtension}", + "${file}" + ], + "group": { + "kind": "build", + "isDefault": true + }, + "problemMatcher": ["$gcc"] + }, + { + "label": "Build with Makefile", + "type": "shell", + "command": "make", + "group": "build" + } + ] +} + +VS Code Debugging (.vscode/launch.json): +---------------------------------------- +{ + "version": "0.2.0", + "configurations": [ + { + "name": "Debug C Program", + "type": "cppdbg", + "request": "launch", + "program": "${workspaceFolder}/build/${fileBasenameNoExtension}", + "args": [], + "stopAtEntry": false, + "cwd": "${workspaceFolder}", + "environment": [], + "externalConsole": false, + "MIMode": "gdb", + "setupCommands": [ + { + "description": "Enable pretty-printing", + "text": "-enable-pretty-printing", + "ignoreFailures": true + } + ], + "preLaunchTask": "Build C Program" + } + ] +} + +================================================================================ +🌿 SCHRITT 5: GIT INITIALISIEREN +================================================================================ + +Git Konfiguration: +------------------ +git config --global user.name "Dein Name" +git config --global user.email "dein.email@example.com" +git config --global init.defaultBranch main + +Git Initialisierung: +-------------------- +cd mein-projekt +git init + +.gitignore erstellen: +--------------------- +# Build artifacts +build/ +*.o +*.exe +*.out +*.a +*.so +*.dll + +# IDE +.vscode/settings.json +.idea/ +*.swp +*.swo +*~ + +# OS +.DS_Store +Thumbs.db + +# Debugging +*.dSYM/ +*.su +*.idb +*.pdb + +Erster Commit: +-------------- +git add . +git commit -m "Initial commit: Projektstruktur" + +================================================================================ +🌐 SCHRITT 6: GITEA/GITHUB VERBINDEN +================================================================================ + +SSH-Key erstellen: +------------------ +ssh-keygen -t ed25519 -C "dein.email@example.com" + +# Public Key anzeigen: +cat ~/.ssh/id_ed25519.pub + +# In Gitea/GitHub einfügen: +# Settings → SSH and GPG keys → New SSH key + +Repository verbinden: +--------------------- +# Für Gitea: +git remote add origin git@gitea.ragtag.rocks:username/repo-name.git + +# Für GitHub: +git remote add origin git@github.com:username/repo-name.git + +# Oder via HTTPS: +git remote add origin https://gitea.ragtag.rocks/username/repo-name.git + +Push: +----- +git push -u origin main + +================================================================================ +📋 SCHRITT 7: TÄGLICHER WORKFLOW +================================================================================ + +1. Änderungen machen + - Code in VS Code bearbeiten + - Speichern (Ctrl+S) + +2. Kompilieren (Ctrl+Shift+B) + - Task: "Build C Program" oder "Build with Makefile" + +3. Testen + - Terminal: ./build/programm + - Oder Debuggen: F5 + +4. Commit + git add . + git commit -m "Beschreibung der Änderungen" + git push + +================================================================================ +🐛 SCHRITT 8: DEBUGGING IN VS CODE +================================================================================ + +Breakpoints setzen: +------------------- +- F9 oder Klick links neben Zeilennummer +- Bedingte Breakpoints: Rechtsklick → "Edit Breakpoint" + +Debugging starten: +------------------ +- F5: Debuggen starten +- F10: Step Over (nächste Zeile) +- F11: Step Into (in Funktion hinein) +- Shift+F11: Step Out (aus Funktion heraus) +- Shift+F5: Stop + +Variablen inspizieren: +---------------------- +- Links im Debug-Panel: Variablen, Watch, Call Stack +- Hover über Variable im Code zeigt Wert +- Debug Console: Ausdrücke auswerten + +================================================================================ +🎯 CHECKPOINT 0: TESTE DEINE UMGEBUNG +================================================================================ + +Aufgabe: Erstelle ein "Hello, World!" Programm + +1. Erstelle Projektstruktur +2. Erstelle src/main.c: + +#include + +int main() { + printf("Hello, World!\n"); + return 0; +} + +3. Erstelle Makefile: +CC = gcc +CFLAGS = -Wall -Wextra -g + +hello: src/main.c + $(CC) $(CFLAGS) -o build/hello src/main.c + +clean: + rm -f build/hello + +4. Kompiliere: make +5. Führe aus: ./build/hello +6. Committe: git add . && git commit -m "Initial: Hello World" +7. Pushe: git push + +================================================================================ +💡 TIPPS & TRICKS +================================================================================ + +VS Code Shortcuts: +------------------ +Ctrl+` Terminal öffnen +Ctrl+Shift+B Build +F5 Debuggen +Ctrl+Space IntelliSense +Ctrl+Click Zur Definition springen +F12 Definition öffnen +Ctrl+/ Zeile kommentieren +Ctrl+D Nächstes Vorkommen auswählen +Ctrl+Shift+L Alle Vorkommen auswählen + +Nützliche Extensions: +--------------------- +- Code Runner: Schnell Code ausführen +- Todo Tree: TODOs im Projekt finden +- Path Intellisense: Autocomplete für Pfade +- Bracket Pair Colorizer: Klammern farbig +- indent-rainbow: Einrückung farbig + +Git in VS Code: +--------------- +- Source Control Panel (Ctrl+Shift+G) +- Änderungen stagen, committen, pushen +- Branches erstellen/wechseln +- Merge-Konflikte lösen + +================================================================================ +🔧 FEHLERBEHEBUNG +================================================================================ + +Problem: "gcc: command not found" +Lösung: PATH überprüfen, Compiler neu installieren + +Problem: "cannot open output file" +Lösung: build/ Verzeichnis erstellen: mkdir build + +Problem: "undefined reference" +Lösung: Linker-Flags hinzufügen (z.B. -lm für Math) + +Problem: Git Permission denied +Lösung: SSH-Key prüfen, remote URL überprüfen + +================================================================================ +📚 WEITERFÜHRENDE RESSOURCEN +================================================================================ + +VS Code C/C++ Tutorial: +https://code.visualstudio.com/docs/languages/cpp + +Git Dokumentation: +https://git-scm.com/doc + +Gitea Dokumentation: +https://docs.gitea.io/ + +Interactive Git Tutorial: +https://learngitbranching.js.org/ + +================================================================================ +✅ BEREIT FÜR MODUL 1? +================================================================================ + +Wenn du: +- [ ] VS Code installiert hast +- [ ] C/C++ Extensions installiert hast +- [ ] Compiler (gcc/g++) funktioniert +- [ ] Git konfiguriert hast +- [ ] Hello World kompiliert und ausgeführt hast +- [ ] Ein Repository erstellt und gepusht hast + +... dann bist du bereit für Modul 1: Das Memory-Modell! + +================================================================================ +*/