Thread overview | ||||||
---|---|---|---|---|---|---|
|
November 29, 2014 Why does hello world not compile in safe? | ||||
---|---|---|---|---|
| ||||
---- import std.stdio; @safe: void main() { writeln("Edit source/app.d to start your project."); } ---- source/app.d(5): Error: safe function 'D main' cannot call system function 'std.stdio.writeln!(string).writeln' |
November 29, 2014 Re: Why does hello world not compile in safe? | ||||
---|---|---|---|---|
| ||||
Posted in reply to Freddy Attachments: | 'cause `writeln`() is not @safe, as you can read in the following
compiler message:
> source/app.d(5): Error: safe function 'D main' cannot call system
> function 'std.stdio.writeln!(string).writeln'
|
November 29, 2014 Re: Why does hello world not compile in safe? | ||||
---|---|---|---|---|
| ||||
Posted in reply to Freddy | On Saturday, November 29, 2014 07:24:55 Freddy via Digitalmars-d-learn wrote:
> ----
> import std.stdio;
> @safe:
> void main()
> {
> writeln("Edit source/app.d to start your project.");
> }
>
> ----
> source/app.d(5): Error: safe function 'D main' cannot call system
> function 'std.stdio.writeln!(string).writeln'
Well, as the error message says, writeln isn't @safe. It's @system. Now, in this case, writeln really should be inferred as @safe, but it looks like whatever work needs to be done to make it so that writeln is treated as @safe when it can be hasn't been done yet (whether it can be or not depends on what's passed to it, so implementing that properly could be rather complicated, but mainly, the issue is that someone needs to take the time to do it).
- Jonathan M Davis
|
November 29, 2014 Re: Why does hello world not compile in safe? | ||||
---|---|---|---|---|
| ||||
Posted in reply to Freddy | Freddy:
> ----
> import std.stdio;
> @safe:
> void main()
> {
> writeln("Edit source/app.d to start your project.");
> }
>
> ----
> source/app.d(5): Error: safe function 'D main' cannot call system
> function 'std.stdio.writeln!(string).writeln'
With the latest dmd compiler this compiles fine.
Bye,
bearophile
|
Copyright © 1999-2021 by the D Language Foundation