diff options
author | Marti Bolivar <mbolivar@mit.edu> | 2010-10-20 06:46:52 -0400 |
---|---|---|
committer | Marti Bolivar <mbolivar@mit.edu> | 2010-10-20 06:46:52 -0400 |
commit | 85c1c72db022bba891868afd3375e39dbe245701 (patch) | |
tree | 9d86a3db825667362a8c89a98a205586015aec94 /source/arduino/define.rst | |
parent | abcfcc62cc62dfc088d30d5a6b6c36d6c89f7b07 (diff) | |
download | librambutan-85c1c72db022bba891868afd3375e39dbe245701.tar.gz librambutan-85c1c72db022bba891868afd3375e39dbe245701.zip |
initial check-in of arduino docs in RST format (converted using wget+pandoc)
Diffstat (limited to 'source/arduino/define.rst')
-rw-r--r-- | source/arduino/define.rst | 83 |
1 files changed, 83 insertions, 0 deletions
diff --git a/source/arduino/define.rst b/source/arduino/define.rst new file mode 100644 index 0000000..6190cb9 --- /dev/null +++ b/source/arduino/define.rst @@ -0,0 +1,83 @@ +.. _arduino-define: + +Define +====== + +``#define`` is a useful C component that allows the programmer to +give a name to a constant value before the program is compiled. +Defined constants in arduino don't take up any program memory space +on the chip. The compiler will replace references to these +constants with the defined value at compile time. + + + +This can have some unwanted side effects though, if for example, a +constant name that had been #defined is included in some other +constant or variable name. In that case the text would be replaced +by the #defined number (or text). + + + +In general, the *`const <http://arduino.cc/en/Reference/Const>`_* +keyword is preferred for defining constants and should be used +instead of #define. + + + +Arduino defines have the same syntax as C defines: + + + +Syntax +------ + +``#define constantName value`` + + + +Note that the # is necessary. + + + +Example +------- + +:: + + #define ledPin 3 + // The compiler will replace any mention of ledPin with the value 3 at compile time. + + + +Tip +--- + +There is no semicolon after the #define statement. If you include +one, the compiler will throw cryptic errors further down the page. + + + +:: + + #define ledPin 3; // this is an error + + + +Similarly, including an equal sign after the #define statement will +also generate a cryptic compiler error further down the page. + + + +:: + + #define ledPin = 3 // this is also an error + + + +See +--- + + +- `const <http://arduino.cc/en/Reference/Const>`_ +- `Constants <http://arduino.cc/en/Reference/IntegerConstants>`_ + |