eles via Digitalmars-d-learn
2014-10-14 13:20:49 UTC
Hello,
According to this:
http://forum.dlang.org/post/lddug4$jgv$***@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?
According to this:
http://forum.dlang.org/post/lddug4$jgv$***@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?