Skip to content

Commit

Permalink
fix hw
Browse files Browse the repository at this point in the history
  • Loading branch information
9il committed Apr 20, 2015
1 parent 07b4844 commit 548923f
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 8 deletions.
8 changes: 4 additions & 4 deletions docs/source/example.rst
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,15 @@ D_ is complex multi-paradigm programming language.
Hellow Wolrd!
~~~~~~~~~~~~~~

To import ``MODULE`` from `C Standard library`_ use ``import core.stdc.MODULE;`` construction.

The following well known С program prints "Hello, World!" to the standard output.

.. literalinclude:: ../../examples/helloworld.c
:language: c
:tab-width: 4

It can be easily translated to D_:

It can be easily translated to D_.
Use ``import core.stdc.MODULE;`` construction to import ``MODULE`` from `C Standard library`_.

.. literalinclude:: ../../examples/helloworld1.d
:language: d
Expand All @@ -27,7 +27,7 @@ It can be easily translated to D_:
.. seealso:: `Programming in D for C Programmers`_.


Phobos_ based "Hello, World!" program looks simpler:
Common D_ "Hello, World!" program based on Phobos_ looks simpler:

.. literalinclude:: ../../examples/helloworld2.d
:language: d
Expand Down
6 changes: 4 additions & 2 deletions examples/helloworld1.d
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
import core.stdc.stdio;

immutable char[] nullTerminatedStr = "Hello, World!\0"; // ends with null!
// ends with null!
immutable char[] nullTerminatedStr = "Hello, World!\0";

int main()
{
puts(nullTerminatedStr.ptr); // calls external C function
// calls external C function
puts(nullTerminatedStr.ptr);
return 0;
}
5 changes: 3 additions & 2 deletions examples/helloworld2.d
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
import std.stdio;

//Deduces the type of a declared variable from its initialization expression
immutable str = "Hello, World!";

void main()
{
//Scoped and selective imports can be used.
import std.stdio : writeln;
writeln(str);
}

0 comments on commit 548923f

Please sign in to comment.