Predefined Macros (__FILE__, __LINE__) in C
The compiler predefines macros carrying compile context: __FILE__ (current filename), __LINE__ (current line), __func__ (enclosing function name, C99), __DATE__/__TIME__ (build timestamp), plus __STDC_VERSION__ for the standard in force. Logging and assertion macros stamp these into every message, pinpointing failures without manual labels.
#error aborts compilation with a message (for impossible configurations), #pragma packs pragmas like packWarning controls, and #line renumbers (mostly for generated code). Together they make diagnostics self-locating.
Location macros
fprintf(stderr, "%s:%d: fail\n", __FILE__, __LINE__); β every message carries its own address.
__func__ names context
Inside any function, __func__ expands to its name string β log helpers include it automatically.
#error for impossible states
#if !defined(HAVE_X)\n#error "need X"\n#endif β unsupported configurations fail loudly at compile time.
Version detection
#if __STDC_VERSION__ >= 201112L gates C11 features β portable code adapts to its compiler.
#include <stdio.h>Β #define LOG(msg) fprintf(stderr, "%s:%d %s\n", __FILE__, __LINE__, msg)Β int main(void) { LOG("starting"); return 0;}Recommended resourcesAffiliate links Β· may earn us a commission
Recommended for learners
Practice what you learned
Re-implement each visualized algorithm in C yourself β building beats watching.