aboutsummaryrefslogtreecommitdiffstats
path: root/source/arduino/sizeof.rst
diff options
context:
space:
mode:
Diffstat (limited to 'source/arduino/sizeof.rst')
-rw-r--r--source/arduino/sizeof.rst45
1 files changed, 22 insertions, 23 deletions
diff --git a/source/arduino/sizeof.rst b/source/arduino/sizeof.rst
index 8513e9d..7c31809 100644
--- a/source/arduino/sizeof.rst
+++ b/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