4 ms·
Plenty of languages provide filenames/line numbers in assertions without using macros. Furthermore, `__LINE__` and `__FILE__` style macros are a pretty safe su
by copsarebastards 12y ago
Plenty of languages provide filenames/line numbers in assertions without using macros.
Furthermore, `__LINE__` and `__FILE__` style macros are a pretty safe subset of macros that aren't really representative of the problems with macros. Compare:
#include <stdlib.h>
#include <stdio.h>
#include "my_macro_library.h"
int main()
{
int x = 0;
printf("%i", increment(x));
printf("%i", __LINE__);
return EXIT_SUCCESS;
}
There are a ton of different implementations of an `increment` macro which are going to cause undefined behavior here. Contrast with the `__LINE__` macro: it's implemented by the compiler and has unsurprising, well-defined behavior.