TOC | Prev | Next

Avoid functions as macros

Macros have no typechecking. It's just text expansion.

Most compilers these days will inline simple functions, so don't
use macros instead of functions in the name of "efficiency."

inline size_t bytes_needed( size_t n, size_t typesize ) {
    return n * typesize;
}

const size_t buffersize = bytes_needed( nusers, sizeof(struct User));

gcc -E will preprocess to stdout, so you can see exactly what
the effects of your macros are.

TOC | Prev | Next