Modularization#
- modular programming
a programming paradigm that emphasizes organizing the functions of a codebase into independent modules β each providing an aspect of a computer program without providing other aspects.
Defining functions#
int square(int n); // Function prototype (typically in .h files)
int square(int n) { // Function definition (typically in .c files)
return n * n;
}
Managing multiple modules in C#
π include/ <= How is a module used?
π lib1.h
π lib2.h
π src/ <= Implementations
π lib1.c
π lib2.c
π main.c
VS Code considerations#
You have to modify:
compile_flags.txt, so that language server can see the header files:-std=gnu2y -g -Iinclude
tasks.json, e.g.,:"command": "clang", "args": [ "'@compile_flags.txt'", "./src/main.c", "./src/lib1.c", "./src/lib2.c", "-o", "main" ],
Alternatively we can use a
makefileand usemakeas the command.