Reference.Const History

Hide minor edits - Show changes to markup

January 06, 2009, at 10:39 PM by Paul Badger -
Changed lines 5-6 from:

Constants defined with the const keyword obey the rules of variable scoping that govern other variables. This, and the pitfalls of #define, makes the const keyword a superior method for defining constants and is preferred over using #define.

to:

Constants defined with the const keyword obey the rules of variable scoping that govern other variables. This, and the pitfalls of using#define, makes the const keyword a superior method for defining constants and is preferred over using #define.

January 06, 2009, at 10:38 PM by Paul Badger -
Deleted line 18:
Changed lines 21-23 from:

You can use either const or #define for creating numeric or string constants. For arrays, you will need to use const.

to:

You can use either const or #define for creating numeric or string constants. For arrays, you will need to use const. In general const is preferred over #define for defining constants.

January 06, 2009, at 10:37 PM by Paul Badger -
Changed lines 5-6 from:

Constants defined with the const keyword obey the rules of variable scoping that govern other variables. This, and the pitfalls of #define makes the const keyword a superior method for defining constants and is preferred over using #define.

to:

Constants defined with the const keyword obey the rules of variable scoping that govern other variables. This, and the pitfalls of #define, makes the const keyword a superior method for defining constants and is preferred over using #define.

January 06, 2009, at 10:36 PM by Paul Badger -
Changed lines 5-6 from:

Constants defined with the const obey the rules of variable scoping that govern other variables, however. This makes the const keyword a superior method for defining constants and is preferred over using #define.

to:

Constants defined with the const keyword obey the rules of variable scoping that govern other variables. This, and the pitfalls of #define makes the const keyword a superior method for defining constants and is preferred over using #define.

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

The const keyword stands for constant. It is a variable qualifier that modifies the behavior of the variable.

const makes a variable "read-only". This means that the variable can be used just as any other variable of its type, but its value cannot be changed. You will get a compiler error if you try to assign a value to a const variable.

to:

The const keyword stands for constant. It is a variable qualifier that modifies the behavior of the variable, making a variable "read-only". This means that the variable can be used just as any other variable of its type, but its value cannot be changed. You will get a compiler error if you try to assign a value to a const variable.

January 06, 2009, at 10:30 PM by Paul Badger -
Changed lines 7-8 from:

Constants defined with const obey the rules of scoping that govern other variables, however. This makes the const keyword a superior method for defining constants and is preferred over using #define.

to:

Constants defined with the const obey the rules of variable scoping that govern other variables, however. This makes the const keyword a superior method for defining constants and is preferred over using #define.

January 06, 2009, at 10:24 PM by Paul Badger -
Changed lines 5-6 from:

const makes a variable "read-only". This means that the variable can be used just as any other variable of its type, but its value cannot be changed. You will get a compiler error if you try to assign a value to a const variable.

to:

const makes a variable "read-only". This means that the variable can be used just as any other variable of its type, but its value cannot be changed. You will get a compiler error if you try to assign a value to a const variable.

Constants defined with const obey the rules of scoping that govern other variables, however. This makes the const keyword a superior method for defining constants and is preferred over using #define.

July 17, 2007, at 08:24 PM by David A. Mellis -
Changed line 26 from:
to:
July 17, 2007, at 06:09 PM by Paul Badger -
Changed lines 5-6 from:

const makes a variable "read-only". This means that the variable can be used just as any other variable of its type, but its value cannot be changed. You will get an error if you try to assign a value to a const variable.

to:

const makes a variable "read-only". This means that the variable can be used just as any other variable of its type, but its value cannot be changed. You will get a compiler error if you try to assign a value to a const variable.

May 31, 2007, at 04:36 PM by David A. Mellis -
Changed lines 3-6 from:

The const keyword stands for constant. Similar to the volatile keyword, it is called a variable qualifier and is used to modify the way the compiler and program treats the variable.

const is used to modify a variable by making it "read-only". This means that the variable can be used just as any other variable of its type, but the value cannot be changed. The compile.r will generate an error if you try to write to a const

to:

The const keyword stands for constant. It is a variable qualifier that modifies the behavior of the variable.

const makes a variable "read-only". This means that the variable can be used just as any other variable of its type, but its value cannot be changed. You will get an error if you try to assign a value to a const variable.

May 31, 2007, at 04:34 PM by David A. Mellis -
Changed lines 22-24 from:

It doesn't make much difference whether you use const or #define keywords for defining single number constants, for arrays and strings though, you will need to use the const qualifier

to:

You can use either const or #define for creating numeric or string constants. For arrays, you will need to use const.

May 31, 2007, at 04:31 PM by David A. Mellis -
Changed lines 18-19 from:

@]]

to:

@]

May 29, 2007, at 10:12 PM by Paul Badger -
Changed lines 22-24 from:

It doesn't make much difference whether you use const or #define keywords for defining single number constants, for arrays and strings? though, you will need to use the const qualifier

to:

It doesn't make much difference whether you use const or #define keywords for defining single number constants, for arrays and strings though, you will need to use the const qualifier

May 29, 2007, at 10:12 PM by Paul Badger -
Changed lines 22-24 from:

It doesn't make much difference whether you use const or #define keywords for defining single number constants, for arrays? and strings? though, you will need to use the const qualifier

to:

It doesn't make much difference whether you use const or #define keywords for defining single number constants, for arrays and strings? though, you will need to use the const qualifier

May 29, 2007, at 10:12 PM by Paul Badger -
Changed lines 22-24 from:

It doesn't make much difference whether you use const or #define keywords for defining single number constants, for arrays? and strings? though, you will need to use the const qualifier

to:

It doesn't make much difference whether you use const or #define keywords for defining single number constants, for arrays? and strings? though, you will need to use the const qualifier

May 29, 2007, at 10:10 PM by Paul Badger -
Changed lines 22-24 from:

It doesn't make much difference whether you use const or #define keywords for defining single number constants, for arrays? and strings? though, you will need to use the const qualifier

to:

It doesn't make much difference whether you use const or #define keywords for defining single number constants, for arrays? and strings? though, you will need to use the const qualifier

May 29, 2007, at 10:09 PM by Paul Badger -
Changed lines 22-24 from:

It doesn't make much difference whether you use const or #define keywords for defining single number constants, for arrays? and strings? though, you will need to use the const qualifier

to:

It doesn't make much difference whether you use const or #define keywords for defining single number constants, for arrays? and strings? though, you will need to use the const qualifier

May 29, 2007, at 10:08 PM by Paul Badger -
Changed lines 3-4 from:

The const keyword stands for constant. It can be used to modify a variable by making it "read-only". This means that the variable can be used just as any other variable of its type, but the value cannot be changed. The compile.r will generate an error if you try to write to a const

to:

The const keyword stands for constant. Similar to the volatile keyword, it is called a variable qualifier and is used to modify the way the compiler and program treats the variable.

const is used to modify a variable by making it "read-only". This means that the variable can be used just as any other variable of its type, but the value cannot be changed. The compile.r will generate an error if you try to write to a const

Changed lines 20-24 from:
to:

#define or const

It doesn't make much difference whether you use const or #define keywords for defining single number constants, for arrays? and strings? though, you will need to use the const qualifier

May 29, 2007, at 09:46 PM by Paul Badger -
Changed line 6 from:
to:

[@

Changed lines 14-21 from:

pi = 7; // illegal - you can't write to (modify) a constant

to:

pi = 7; // illegal - you can't write to (modify) a constant

@]]

See also:

May 29, 2007, at 09:45 PM by Paul Badger -
Added lines 1-14:

const keyword

The const keyword stands for constant. It can be used to modify a variable by making it "read-only". This means that the variable can be used just as any other variable of its type, but the value cannot be changed. The compile.r will generate an error if you try to write to a const

Example

const float pi = 3.14; float x;

// ....

x = pi * 2; // it's fine to use const's in math

pi = 7; // illegal - you can't write to (modify) a constant

Share