Modular C
Public Wrapper
A wrapper function can present a small interface over lower-level details.
Public Wrapper
public_wrapper.c
#include <stdio.h>
static int rectangle_area(int width, int height) {
return width * height;
}
int main(void) {
int width = ;
int height = 5;
int area = rectangle_area(width, height);
printf("area=%d\n", area);
return 0;
}
#include <stdio.h>
static int rectangle_area(int width, int height) {
return width * height;
}
int main(void) {
int width = ;
int height = 5;
int area = rectangle_area(width, height);
printf("area=%d\n", area);
return 0;
}
#include <stdio.h>
static int rectangle_area(int width, int height) {
return width * height;
}
int main(void) {
int width = ;
int height = 5;
int area = rectangle_area(width, height);
printf("area=%d\n", area);
return 0;
}
interface function
The caller uses a simple function name instead of repeating the formula.
implementation detail
The formula can change inside the wrapper without changing the call site.