C Deep Dive

A close look at the C language.

Here, we will go through all the nitty-gritty details to know about C. No algorithms, just a deep dive into how the language works.

Versions of C

C89 and C99 are two prominent standards for the C programming language, each introducing features and defining the language's behavior.

C23 (ISO/IEC 9899:2024) the current open standard for C, published in October 2024. It includes enhancements such as improved const support, new and updated library functions, and further compiler optimizations.

Running C

Here is the command to run a simple C program:

> gcc hello.c -o hello 
> ./hello

The first line compiles and creates an executable file named hello. The second line runs the program. In Windows, the second line should just be hello.

gcc refers to the GNU Compiler Collection (GCC) is a compiler system produced by the GNU Project supporting various programming languages. The output file is the executable file called assembler output.

You can use this trick to both compile and run your code with one command:

gcc zork.c -o zork && ./zork

Note: Use the -Wall option to turn on all warnings.

Note: If -o is not provided, then the default name of the compiled file is a.out.

C to assembly

It is possible to have a look at the output of the C compiler using the objdump command line utility.

objdump is primarily a reverse engineering and debugging tool that helps programmers understand how their C source code is translated into machine code. 

For example, when the compiled file is Tester then we can use the following command:

objdump Tester -d

to see the code presented in assembly. The output will display the assembly code with the relevant lines from your hello.c file interspersed, providing detailed insight into the compilation process. 

Here are the flags that can be used with this command:

-f          # display header information for the entire file
-s          # display per-section summary information
-d          # disassemble sections containing code
--source    # (implies -d) show source code, if available, along with disassembly

To do this in a web interface, you can use https://godbolt.org/.

C debugger (gdb)

To load the code into the debugger, use gdb <fileName>. Then, to get the debugger running, use:

start # start debugging
break n # set breakpoint at line n
continue # Continue the execution till the next breakpoint
step # for step by step execution
layout src # to see source code in separate window
layout asm # to see compiled assembly instructions
print <var> # to see the value of the variable
stop # stop debugging
quit # exit gdb

The first thing to know about C is that is is defined to create small, fast solutions. It is used to write code that’s a lot closer to what machines really understand.

Syntax in C
Operators in C
Statements in C
Pointers in C
Dynamic Memory Allocation in C
Types in C
Data Structures in C
Functions in C
File handling in C

/ Continue

Follow the technical trail.

Use the dense notes as the source material, then move through the guided route, writing, or project proof when you want a cleaner entry point.