When betterC triggers errors in compilation?

eles via Digitalmars-d-learn digitalmars-d-learn at puremagic.com
Tue Oct 14 06:20:49 PDT 2014


Hello,

According to this:

http://forum.dlang.org/post/lddug4$jgv$1@digitalmars.com

"-betterC" should disable support for exception handling. So I 
expected dmd to reject the following code:

===============================================
import std.stdio;

int readDieFromFile()
{
     auto file = File("the_file_that_contains_the_value", "r");

     int die;
     file.readf(" %s", &die);

     return die;
}

int tryReadingFromFile()
{
     int die;

     try {
         die = readDieFromFile();

     } catch (std.exception.ErrnoException exc) {
         writeln("(Could not read from file; assuming 1)");
         die = 1;
     }

     return die;
}

void main()
{
     const int die = tryReadingFromFile();

     writeln("Die value: ", die);
}
=======================================================
(from Ali's book; thanks once again)

But it compiles and runs fine:

$dmd betterC.d -betterC

$./betterC
(Could not read from file; assuming 1)
Die value: 1

This is with dmd 2.066 on Linux x86_64.

What code would fail under -betterC and how?


More information about the Digitalmars-d-learn mailing list