Fading Coder

One Final Commit for the Last Sprint

Fundamentals of C Programming Language

Compilation Process in Linux C C Compilers GNU GCC Microsoft Visual C++ (MSVC) Apple Clang Intel C++ Compiler Default Linux compiler: cc Programming Language Classification Compiled Languages (C, C++, Java) Convert source code to machine instructions Perform type safety checks High performance Less...

Character, String, and Memory Functions in C

Character Classification Functions C provides a comprehensive set of functions for character classification through the <ctype.h> header. These functions determine the category of a given character. Classification Functions Reference Function Condition for True Return iscntrl Control character...

Configuring Clang-Format for K&R C/C++ Style

#include "custom_driver.h" #include "system_bus.h" #include <algorithm> #include <deque> #include <list> #include <memory> //! Header grouping + sorting #include <unordered_map> //! Macro continuation aligned right #define LOG_VERBOSE_DATA(sender, ms...

Counting Leading Zeros in C: GCC Built-ins and MSVC Alternatives

When evaluating __builtin_clz with an input of 0, the output often matches the result of passing 1 (yielding 31 on a 32-bit integer), which seems counterintuitive. According to the GCC documentation, the result of __builtin_clz is explicitly undefined when the enput is 0: Returns the number of leadi...

Pointers and Arrays in C: Memory Safety and Multi-dimensional Access

1. Segmentation Faults When executing C programs, ancountering "segmentation fault" errors can be frustrating due to their vague nature. Here are the common causes and patterns leading to these crashes. 1.1 Wild Pointers Uninitialized Pointers: Declaring a pointer without assigning a valid...

Handling Variable Declarations within Switch Statements in C and C++

When declaring variables inside a case block of a switch statement, specific compiler behaviors in C and C++ must be considered. The following code illustrates a commmon issue: switch (input_value) { case FIRST_CASE: int local_var = 100; case SECOND_CASE: // Additional code break; default: // Defaul...

Building Static and Shared Libraries with GCC on Linux

Static libraries bundle multiple object files into a single archive, while shared libraries defer symbol resolution until load or runtime. Both forms are comon on Linux and can be produced with GCC and standard binutils. Inspecting a system static library Static archives are regullar files with the...

Building a C MQTT Client with libmosquitto: Publish/Subscribe Patterns and Topic Filtering

MQTT uses a broker-centric model: all data flows through a broker, while clients act as publishers, subscribers, or both. A single process can publish and subscribe at the same time without being a broker itself. A common pitfall is subscribing and publishing to the same topic from one client. Many...

Linux C/C++ Socket Programming by Example: TCP/UDP Chat, select, Threads, Timers, and fork

TCP Chat over a Local Network Minimal TCP Echo Server (C) #include <arpa/inet.h> #include <errno.h> #include <netinet/in.h> #include <stdio.h> #include <stdlib.h> #include <string.h> #include <sys/socket.h> #include <sys/types.h> #include <unistd.h&...

Implementing a Minimal Passive-Mode FTP Client in C

Implementing a client for the FTP control and data channels requires speaking a simple, line-oriented, text protocol over TCP. Commands are ASCII lines terminated by CRLF (\r\n). Replies are lines beginning with a three-digit code followed by text and CRLF. Only the numeric code is needed for flow c...