3 ms·
> Some compilers offer debug strings in macros, which cannot be used in functions: __FILE__, __LINE__, __func__. But... Of course they can. They are just symbo
by tomsmeding 9y ago
> Some compilers offer debug strings in macros, which cannot be used in functions: __FILE__, __LINE__, __func__.
But... Of course they can. They are just symbols defined by the compiler, and have nothing to do with being in a macro expansion or not. Heck, they are probably implemented as macro's themselves inside the preprocessor.
- jstimpfle 9y agoWhat he means is, you want to use them in a macro. You can't get the effect you probably want by using them in a function. Compare: #define LOG_ERROR() printf("ERROR at %s:%d\n", __FILE__, __LINE__) void logError(void) { printf("ERROR at %s:%d\n", __FILE__, __LINE__); }
- tomsmeding 9y agoSure, they are pretty useless in a function. But that doesn't mean that the author can go and use incorrect language. :P
- AstralStorm 9y agoExcept when they work properly when fully inlined. (Sprinkle GCC/Clang magic here. It is required to make it work.)
- tomsmeding 9y agoIs that even possible? It shouldn't be without extensions. (But that seems to be what you're implying anyway.)