aboutsummaryrefslogtreecommitdiffstats
path: root/docs/source/arduino/sizeof.rst
diff options
context:
space:
mode:
authorMarti Bolivar <mbolivar@mit.edu>2010-11-21 01:40:37 -0500
committerMarti Bolivar <mbolivar@mit.edu>2010-11-21 01:40:37 -0500
commit19e8336afbc827378216aca2b1af45ef89a108ab (patch)
tree5aeb911d2f697ab3bf6ad9cf3609c19fe7a83346 /docs/source/arduino/sizeof.rst
parentb2653be281539928a7ba92433fe2b7c2e3ef4cd4 (diff)
downloadlibrambutan-19e8336afbc827378216aca2b1af45ef89a108ab.tar.gz
librambutan-19e8336afbc827378216aca2b1af45ef89a108ab.zip
updated serial bootloader spec; other improvements
Diffstat (limited to 'docs/source/arduino/sizeof.rst')
-rw-r--r--docs/source/arduino/sizeof.rst45
1 files changed, 22 insertions, 23 deletions
diff --git a/docs/source/arduino/sizeof.rst b/docs/source/arduino/sizeof.rst
index 8513e9d..7c31809 100644
--- a/docs/source/arduino/sizeof.rst
+++ b/docs/source/arduino/sizeof.rst
@@ -5,28 +5,20 @@
sizeof()
========
-Syntax
-------
+The ``sizeof`` operator on the Maple returns the number of bytes
+needed to store a value of a given type\ [#fcharsize]_. This can be
+an ordinary numeric type, like ``int``. It can be something more
+complicated, like a ``struct`` or ``union``. If the argument to
+``sizeof`` is an array, it returns the total number of bytes occupied
+by the array.
-::
+The general syntax looks like this::
sizeof(type)
sizeof(var)
-
-
-Description
------------
-
-The ``sizeof`` operator returns the number of bytes needed to store a
-value of a given type. This can be an ordinary numeric type, like
-``int``. It can be something more complicated, like a ``struct`` or
-``union``. If the argument to ``sizeof`` is an array, it returns the
-total number of bytes occupied by the array.
-
-
-Examplec
---------
+Example
+-------
The ``sizeof`` operator is useful for dealing with arrays (such as
strings) where it is convenient to be able to change the size of the
@@ -51,15 +43,22 @@ changing the text phrase::
}
-Note that ``sizeof`` returns the total number of bytes; this is equal
-to the number of ``char``\ s only because the C++ standard guarantees
-that ``sizeof(char) == 1``. So for larger variable types such as
-``int``, the :ref:`for loop <arduino-for>` would look something like
-this::
+Note that ``sizeof`` returns the total number of bytes. So for larger
+variable types such as ``int``, the :ref:`for loop <arduino-for>`
+would look something like this::
for (i = 0; i < (sizeof(myInts)/sizeof(int)) - 1; i++) {
// do something with myInts[i]
}
+.. rubric:: Footnotes
+
+.. [#fcharsize] Technically (and pedantically) speaking, ``sizeof``
+ returns a multiple of the number of bits a ``char`` occupies in
+ memory. However, on the Maple (this goes for most C++
+ implementations), a ``char`` occupies 8 bits = 1 byte. All the C++
+ standard guarantees, however, is that a ``char`` occupies at
+ *least* 8 bits.
+
+.. include:: cc-attribution.txt
-.. include:: cc-attribution.txt \ No newline at end of file