Overview
The0x00-hello_world module introduces you to C programming fundamentals. You’ll learn about the compilation process, write your first C programs using puts and printf, and understand data type sizes.
Compilation Process
C programs go through multiple stages before becoming executable files. Understanding these stages is crucial for debugging and optimization.Preprocessing
The preprocessor handles directives like#include and #define, expanding them before compilation.
0-preprocessor
Compilation to Object Code
The compiler translates C code to object code without linking.1-compiler
.o file containing machine code that isn’t yet executable.
Assembly Generation
Generate assembly language code to see the low-level instructions.2-assembler
Creating Executables
Compile and link to create an executable with a custom name.3-name
The
-o flag specifies the output filename. Without it, gcc defaults to a.out.Your First C Programs
Using puts()
Theputs() function outputs a string followed by a newline.
4-puts.c
Using printf()
Theprintf() function provides formatted output with more control.
5-printf.c
printf()requires explicit\nfor newlinesprintf()supports format specifiers (%d,%s, etc.)puts()is simpler for plain strings
Data Type Sizes
Understanding data type sizes is essential for memory management and choosing appropriate types.6-size.c
Typical Data Type Sizes
Typical Data Type Sizes
char: 1 byte (8 bits)int: 4 bytes (32 bits)long int: 4 or 8 bytes (platform-dependent)long long int: 8 bytes (64 bits)float: 4 bytes (32 bits)
The
sizeof operator returns the size in bytes. Sizes may vary between 32-bit and 64-bit systems.Compilation Standards
All programs in this module follow the Betty style and compile with strict flags:-Wall: Enable all common warnings-Werror: Treat warnings as errors-Wextra: Enable extra warnings-pedantic: Enforce strict ISO C standard-std=gnu89: Use GNU89 C standard
Best Practices
Common Issues
Compilation errors with -Werror
Compilation errors with -Werror
The
-Werror flag converts warnings to errors. Common issues:- Unused variables
- Missing return statements
- Implicit function declarations
Missing newline in output
Missing newline in output
Remember that
printf() doesn’t add a newline automatically. Always include \n when needed.