Deprecate C style declerations?
Pragma
ericanderton at yahoo.removeme.com
Thu Dec 21 14:04:58 PST 2006
Thomas Kuehne wrote:
>
> Does anyone actually use the #line construct?
YES!
It's extremely handy whenever you're writing something that's generating
D code, especially when you allow chunks of D code through to the
output. For example, I used it extensively while researching for DSP,
and I plan on using it for Enki's codegen (when I get around to it).
A more concrete, if not contrived, example would be a PHP-style
(pre)processor for D:
<html><body>
<?
int value = toInt(url["value"]);
auto result = Fibonacci(value);
?>
The Fibonacci sequence for <?=value?> is <?=result?>
</body></html>
This would emit code (presumably to be run like an applet), like so:
// output.d
echo("<html><body>
");
#line 3 source.dhp
int value = toInt(url["value"]);
auto result = Fibonacci(value);
echo("The Fibonacci sequence for ");
#line 5 source.dhp
echo(value);
echo(" is ");
#line 5 source.dhp
echo(result);
echo("
</body></html>");
This way, any errors in the <??> expressions can be tied back to the
original source, should there be a compiler error.
--
- EricAnderton at yahoo
More information about the Digitalmars-d
mailing list