Uphill

via Digitalmars-d digitalmars-d at puremagic.com
Mon Jun 1 11:23:14 PDT 2015


On Monday, 1 June 2015 at 17:17:18 UTC, Ola Fosheim Grøstad wrote:
> On Monday, 1 June 2015 at 16:57:00 UTC, Jonathan M Davis wrote:
>> I use macros for stuff like exceptions all the time - e.g.
>>
>> THROW(MyException, ("This value is wrong: %d", foo));
>
> ick! Yes,  if you want stack-trace like information in 
> release-builds you need to use the macro system, but that's 
> because __FILE__ and __LINE__ are macros! That's a C deficiency.

The SAD thing here is that C++ actually do expensive stack 
introspection to unwind the stack based on return address, so the 
C++ runtime _could_ have been designed to look up call site 
information down the stack at runtime for "low additional cost" 
even with separate compilation, just like a high level language 
with stack introspection (in Python: 
"inspect.stack()[1][0].f_lineno").

Not saying it is a good idea for a  system level language, but 
there is no technical reason to have macro warts like __LINE__ 
since the full C++ runtime already is bloated. And they could 
have gotten around it with by adding compile time introspection 
to the language too.

I'd say C has embraced macros for good reasons, as a minimalistic 
language design strategy  (newest C version using it for 
generics), but C++ has no longer an excuse for providing it.


More information about the Digitalmars-d mailing list