C
Beginner
1 min read
#define, #include, and Object-Like Macros
Example
/*
* config.h — demonstrates header guard and object-like macros
*/
#ifndef CONFIG_H
#define CONFIG_H
/* Version information */
#define VERSION_MAJOR 2
#define VERSION_MINOR 5
#define VERSION_PATCH 1
#define VERSION_STR "2.5.1"
/* Buffer sizes */
#define MAX_PATH_LEN 260
#define MAX_LINE_LEN 1024
#define MAX_USERS 512
/* Computed macro — parentheses prevent operator-precedence bugs */
#define KB(n) ((n) * 1024)
#define MB(n) (KB(n) * 1024)
#endif /* CONFIG_H */