Is there a way to use only one define statement for this header, without changing the function-like macro into a function?
#define MIN(x, y) ((x) > (y) ? (y) : (x))
#define PI 3.14159
Your approach would be fine - it's sufficient to guard against doubly defining macro. Adding a definition guard is usually useful if you want to protect an entire file. This serves to both shorten the code (as you don't have to guard each macro independently) and to make sure you have consistent definitions (e.g., if you want to make sure
MAX are defined together). E.g.:
#ifndef MY_H #define MY_H #define MIN(x, y) ((x) > (y) ? (y) : (x)) #define MAX(x, y) ((x) < (y) ? (y) : (x)) #define PI 3.14159 #endif
If you just have a single macro/constant you want to define, you can guard it by its own definition, like @Danh suggested.