Reference.Define History

Hide minor edits - Show changes to markup

January 06, 2009, at 10:20 PM by Paul Badger -
Changed lines 3-9 from:

#define is a useful C component that allows you 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 was included in some other constant or variable name.

In general the const is preferred for defining constants and should be used instead of #define.

to:

#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 keyword is preferred for defining constants and should be used instead of #define.

January 06, 2009, at 10:17 PM by Paul Badger -
Added lines 6-9:

This can have some unwanted side effects though, if for example, a constant name that had been #defined was included in some other constant or variable name.

In general the const is preferred for defining constants and should be used instead of #define.

January 06, 2009, at 10:14 PM by Paul Badger -
Added line 34:
September 06, 2008, at 08:31 PM by Paul Badger -
Changed lines 26-27 from:

Similarly including an equal sign after the #define statement will also generate a cryptic compiler error further down the page.

to:

Similarly, including an equal sign after the #define statement will also generate a cryptic compiler error further down the page.

September 06, 2008, at 08:30 PM by Paul Badger -
Changed lines 23-24 from:

#define ledPin 3; // this is an error

to:
#define ledPin 3;    // this is an error 
Changed lines 28-31 from:

#define ledPin = 3 // this is also an error

to:
#define ledPin  = 3  // this is also an error 

September 06, 2008, at 08:29 PM by Paul Badger -
Changed lines 23-24 from:

#define ledPin 3; // this is an error

to:

#define ledPin 3; // this is an error

Changed lines 27-30 from:

#define ledPin = 3 // this is also an error

to:

#define ledPin = 3 // this is also an error

September 06, 2008, at 08:29 PM by Paul Badger -
Changed lines 17-18 from:

//The compiler will replace any mention of ledPin with the value 3 at compile time.@]

to:

// The compiler will replace any mention of ledPin with the value 3 at compile time.@]

September 06, 2008, at 08:28 PM by Paul Badger -
Added lines 22-30:

#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

April 26, 2007, at 05:59 AM by Paul Badger -
Changed line 22 from:

See

to:

See

April 26, 2007, at 05:59 AM by Paul Badger -
Changed lines 20-21 from:

There is no semicolon after the #define statement and the compiler will throw cryptic errors further down the page if you include one.

to:

There is no semicolon after the #define statement. If you include one, the compiler will throw cryptic errors further down the page.

April 26, 2007, at 05:58 AM by Paul Badger -
Changed line 3 from:

=#=define is a useful C component that allows you to give a name to a constant value before the program is compiled.

to:

#define is a useful C component that allows you to give a name to a constant value before the program is compiled.

April 26, 2007, at 05:57 AM by Paul Badger -
Changed line 3 from:
  1. define is a useful C component that allows you to give a name to a constant value before the program is compiled.
to:

=#=define is a useful C component that allows you to give a name to a constant value before the program is compiled.

April 26, 2007, at 04:26 AM by Paul Badger -
Changed lines 1-3 from:

Define

define is a useful C component that allows you to give a name to a constant value before the program is compiled.

to:

Define

  1. define is a useful C component that allows you to give a name to a constant value before the program is compiled.
Changed lines 22-23 from:
to:
April 16, 2007, at 08:23 AM by Paul Badger -
Changed lines 3-5 from:
  1. define is a useful C component that allows you 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 just replace references to these constants with the defined value at compile time.

to:

define is a useful C component that allows you 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.

Changed lines 16-19 from:

#define ledPin 3

The compiler will replace any mention of ledPin with the value 3 at compile time.

to:
#define ledPin 3
//The compiler will replace any mention of ledPin with the value 3 at compile time.
April 16, 2007, at 08:20 AM by Paul Badger -
Changed lines 1-2 from:

Defines

to:

Define

Changed lines 4-6 from:

You can define numbers in arduino that don't take up any program memory space on the chip.

to:

Defined constants in arduino don't take up any program memory space on the chip. The compiler will just replace references to these constants with the defined value at compile time.

Changed lines 8-11 from:

#define constantName value

Note that the # is necessary. For example:

to:

Syntax

#define constantName value

Note that the # is necessary.

Example

April 16, 2007, at 08:16 AM by Paul Badger -
Changed lines 13-14 from:

#define ledPin 3

to:

#define ledPin 3

April 16, 2007, at 08:16 AM by Paul Badger -
Changed lines 3-6 from:

A define a useful C component that allow you to give a name to a value before the program is compiled.

You can define numbers in arduino that don't take up any program memory space on the chip. Arduino defines have the same syntax as C defines:

to:
  1. define is a useful C component that allows you to give a name to a constant value before the program is compiled.

You can define numbers in arduino that don't take up any program memory space on the chip.

Arduino defines have the same syntax as C defines:

April 16, 2007, at 08:11 AM by Paul Badger -
Changed line 15 from:

Common Programming Errors

to:

Tip

April 14, 2007, at 07:42 AM by Paul Badger -
Changed lines 13-14 from:

The compiler will replace any mentions of ledPin with the value 3 at compile time.

to:

The compiler will replace any mention of ledPin with the value 3 at compile time.

Common Programming Errors

There is no semicolon after the #define statement and the compiler will throw cryptic errors further down the page if you include one.

March 31, 2006, at 10:45 PM by Jeff Gray -
Changed lines 1-2 from:

Defines

to:

Defines

March 27, 2006, at 09:12 PM by Tom Igoe -
Changed lines 13-15 from:

The compiler will replace any mentions of ledPin with the value 3 at compile time.

to:

The compiler will replace any mentions of ledPin with the value 3 at compile time.

Reference Home

March 27, 2006, at 09:11 PM by Tom Igoe -
Added lines 1-13:

Defines

A define a useful C component that allow you to give a name to a value before the program is compiled.

You can define numbers in arduino that don't take up any program memory space on the chip. Arduino defines have the same syntax as C defines:

#define constantName value

Note that the # is necessary. For example:

#define ledPin 3

The compiler will replace any mentions of ledPin with the value 3 at compile time.

Share