Add Comment comparison and simple casting comparison

This commit is contained in:
jlp765 2016-09-05 21:41:47 +10:00
parent f616d27fde
commit c2dac56912
1 changed files with 79 additions and 1 deletions

View File

@ -126,7 +126,49 @@ Note: Code examples are not exactly one-to-one, there may be subtle differences
<th>C</th><th>Nim</th><th>Comment</th> <th>C</th><th>Nim</th><th>Comment</th>
</tr> </tr>
<tr>
<td>
<pre>
/* This is a single-line comment */
int x = 3; // another single-line comment
// So is this
</pre>
<pre>
/*
a multi-line comment
*/
//
// or maybe this way?
//
#if 0
some code including comments to be ignored
#endif
</pre>
</td>
<td>
<pre>
# This is a single-line comment
var x = 3 # another comment
</pre>
<pre>
discard """
a multi-line comment
"""
#
# or maybe this way?
#
when false:
a multi-line comment
(but must be indented to be included)
</pre>
</td>
<td>
<b>Single line comments</b>. Use the hash char (#).
<br>
<br>
<b>Multi-line comments</b>. Readability vs easy of use?
</td>
</tr>
<tr> <tr>
<td> <td>
<pre> <pre>
@ -304,5 +346,41 @@ proc foobar(a: ref TPerson) =
<td><b>Dereference.</b> <i>In C, only the pointer to the strings in the struct is copied. In Nim, the string is also copied, but refs are not deep-copied.</i> </td> <td><b>Dereference.</b> <i>In C, only the pointer to the strings in the struct is copied. In Nim, the string is also copied, but refs are not deep-copied.</i> </td>
</tr> </tr>
<tr>
<td>
<pre>
double d = 3.1415926;
int i = (int) d;
d = (double) i;
printf(%d, %g\n", i, d);
</pre>
<pre>
int x = 42;
void *p = &x;
int y = (int) *p;
printf("%d, %d, %p\n", x, y, p);
</pre>
</td>
<td>
<pre>
var d: float = 3.1415926
var i = d.int
d = i.float
echo i, " ",d
</pre>
<pre>
var
x = 42
p: pointer = x.addr
y = cast[ptr int](p)[]
echo x, " ", y, " ", repr(p)
</pre>
</td>
<td>
<b>Simple casting</b> Considered unsafe in Nim (and that you know what you are doing).
<br>
cast is NOT for numeric type conversion.
</td>
</tr>
</table> </table>