883 B
883 B
| tags | |
|---|---|
|
In order to create a file that you can import into other C files you need to create a header file.
Remember that this isn't really a module since
.hfiles and#includesare just text substition
In fact you create a .h header file which links to a .c file which actually
contains the code you want to import.
Let's say we want to create a "module" that handles connecting to WiFi:
// wifi.h
#ifndef WIFI_H
#define WIFI_H
void wifi_connect(void);
#endif
In the .h file we just define the function signature and put checks (so it
doesn't get redefined).
Then the implementation file:
// main/wifi.c
// Add any header files or auxiliary functions that the main (wifi_connect)
// function will require here
void wifi_connect(void) {}
Then in your main entrypoint:
// main/main.c
#include "wifi.h"
wifi_connect()