diff --git a/Nim-for-C-programmers.md b/Nim-for-C-programmers.md index 4954b61..c084cd1 100644 --- a/Nim-for-C-programmers.md +++ b/Nim-for-C-programmers.md @@ -126,7 +126,49 @@ Note: Code examples are not exactly one-to-one, there may be subtle differences CNimComment - + + +
+/* This is a single-line comment */
+int x = 3;  // another single-line comment
+// So is this
+
+
+/*
+a multi-line comment
+*/
+//
+// or maybe this way?
+//
+#if 0
+    some code including comments to be ignored
+#endif
+
+ + +
+# This is a single-line comment
+var x = 3   #  another comment
+
+
+discard """
+a multi-line comment
+"""
+#
+# or maybe this way?
+#
+when false:
+  a multi-line comment 
+  (but must be indented to be included)
+
+ + +Single line comments. Use the hash char (#). +
+
+Multi-line comments. Readability vs easy of use? + +
@@ -304,5 +346,41 @@ proc foobar(a: ref TPerson) =
 Dereference. 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. 
   
 
+  
+
+
+double d = 3.1415926;
+int i = (int) d;
+d = (double) i;
+printf(%d, %g\n", i, d);
+
+
+int x = 42;
+void *p = &x;
+int y = (int) *p;
+printf("%d, %d, %p\n", x, y, p);
+
+ + +
+var d: float = 3.1415926
+var i = d.int
+d = i.float
+echo i, " ",d
+
+
+var 
+  x = 42
+  p: pointer = x.addr
+  y = cast[ptr int](p)[]
+echo x, " ", y, " ", repr(p)
+
+ + +Simple casting Considered unsafe in Nim (and that you know what you are doing). +
+cast is NOT for numeric type conversion. + + \ No newline at end of file