On Monday, 24 August 2015 at 06:17:06 UTC, Jacob Carlborg wrote:
On 2015-08-21 23:55, Walter Bright wrote:
I don't understand why the C++ committee, in its quest to
improve the
language, has not pushed forward with proper replacements for
typical
preprocessor uses, with the intent of eventually deprecating
it entirely.
With modules being already implemented in Clang, is there a
legitimate use case for the preprocessor left?
I use it all the time for handling log messages and throwing
exceptions. Without that, you can't get stuff like the current
file and line number, because C++ isn't smart enough to use the
call point for __FILE__ and __LINE__. So, you either use macros
so that the code _is_ at the call point, or you have to do it
manually, and no one is going to do that sort of thing manually.
I'm sure that there are other use cases, but those are the ones
that I use all the time.
Also, in my experience, getting static or global variables to
work with dlls when you need them is hell, so it pretty much
inevitably comes down to either using a macro or making it a
function with a static variable inside it which it returns. I
usually go with the useless function, but the macro sure seems
tempting sometimes.
To really replace macros - especially in a language that's
already using them - you pretty much have to replace every use
case for them, and I really don't see that happening to C++.
Also, getting rid of macros would break C compatibility, which
they won't do. Even if they add better alternatives to the
language and recommend that you use those instead, they'll still
support macros because of C.
- Jonathan M Davis