Posts

C Language – An Integrated Example (The Five Grammatical Elements of a Programming Language)

1. Integrated Example The following example is a comprehensive example that uses all five grammar elements of the C programming language (variables, operators, statements, control, and functions) and includes all 32 reserved keywords and 12 preprocessor directives under the C90 standard in a single compilable source file. from C Language - Programming Language Grammar exam.c /* * exam.c - Comprehensive C grammar example * */ // #include - include C headers #include <stdio.h> #include <stdlib.h> // #define - define macro #define MAX_COUNT 5 #define BUF_SIZE 64 #define DEBUG_LEVEL 0 // #undef - undefine macro #undef DEBUG_LEVEL #define DEBUG_LEVEL 1 // #ifndef / #endif - compile only if macro is not defined #ifndef RELEASE #define RELEASE #endif // #if / #elif / #else / #endif - conditional compilation #if DEBUG_LEVEL == 0 #define BUILD_TYPE "Release" #elif DEBUG_LEVEL == 1 #define BUILD_TYPE "Debug" ...

Understanding Executable File Modification and Protection

Image
1. Executable File Structure We have already examined the structure of executable files through the following topic. How an Executable File Operates Just like document files are organized in a defined format, executable files also have a similar structured format. Among their components, the machine code in the .text section is loaded and executed . 2. Modifying an Executable File This means that by directly modifying the machine code stored in the .text section , the execution behavior of a program can be changed. Using this characteristic, it is possible to alter the execution result without modifying the program source code. 2.1. bin to hex Use the xxd command to convert an executable file into a text-based hex file. $ objdump -d -M intel add Disassembly of section .text: 0000000000401000 <_start>: 40...

C Language – Variable Data Types

Image
1. C Data Types signed unsigned short long char int float double auto register static extern const volatile 1.1. Integer Sign Modifiers These are generally used in combination with integer types such as char or int .  They can also be used alone, in which case they are interpreted as having an implied int . signed unsigned signed and unsigned are keywords that determine whether an integer type can represent negative values. signed uses a sign bit to represent both negative and positive values. unsigned does not represent negative values and only represents values greater than or equal to 0. Even with the same 1 byte (8 bits), the range of values differs depending on whether it is signed or unsigned . 1.2. Integer Size Modifiers These are generally used in combination with the integer type int .  They can also be used alone, in which case they are interpreted as having an implied int . short long short short is a modifier used to reduce th...

C Language - The Grammar of a Programming Language

Image
1. Language Grammar Human language has a wide variety of grammar , and learning it requires a great deal of time. You need to learn many grammatical elements such as nouns, verbs, tense, and word order. A programming language is a language with the clear purpose of instructing a computer what to do and how to do it. Even with a relatively small number of grammatical elements, it is possible to express meaning and execute actions. Unlike human language, a programming language can be used immediately once you understand a few core grammar rules . 2. C Language Grammar A programming language consists of the following five elements. Variables - store values. Operations - calculate values. Statements - execute content. Control - change the order of execution. Functions - group multiple statements into one. Understanding just these five grammar elements is enough to understand the basic structure of a program. 2.1. Variables A variable is a memory space that store...

C Language – Starting with “Hello, World!”

Image
1. Installing the C Compiler The most widely used compiler for developing C programs in a Linux environment is GCC (GNU Compiler Collection). While it can be installed individually, it is more efficient to install it via the build-essential package, which includes a collection of essential development tools. $ sudo apt update $ sudo apt install -y build-essential $ gcc --version gcc ... $ make --version GNU Make ... GCC (GNU Compiler Collection) : The standard C compiler in Linux environments. build-essential : A package that installs essential development tools at once, including GCC, g++ (C++ compiler), make (build automation tool), and libc6-dev (standard libraries and headers). 2. The First Program Since the example of printing “Hello, world!” was introduced in the 1978 book The C Programming Language [1] , this phrase has been widely used as the most basic introductory example in programming textbooks across almost all programming la...