| const |
|
grammar |
| |
A qualifier for declarations that affects the permissions of the
variable being declared by taking away write permission.
A
const
variable cannot be re-assigned, but if the variable is a pointer, the
permissions of the target object are unaffected.
So, a
const int
is completely unchangeable, but a
const Array
can have its elements re-assigned.
When
const
is used as part of a declaration,
its usage description can be summarized as follows:
Declaration:
const name DeclaratorList
| |
| Example: |
This example indicates the effect of
const
on a
String.
import yoix.stdio.*;
import yoix.string.*;
const String str[5,8] = "hello";
fprintf(stdout, "Initial value of 'str' is '%s'.\n", str);
try {
str = "re-assign pointer";
}
catch(e) {
fprintf(stdout, "We could not point 'str' to something else.\n");
return(true);
}
*str = 'j';
fprintf(stdout,
"However, we changed that to which 'str' points to '%s'\n",
str);
overlay(str, "goodbye");
fprintf(stdout, "and can even grow it to '%s'\n", str);
try {
overlay(str, "overdoing it");
}
catch(e) {
fprintf(stdout,
"since 'const' only affects the pointer permissions.\n");
return(true);
}
The results of this example on standard output are:
Initial value of 'str' is 'hello'.
We could not point 'str' to something else.
However, we changed that to which 'str' points to 'jello'
and can even grow it to 'goodbye'
since 'const' only affects the pointer permissions.
| | |
| See Also: |
final,
reference
|
|
Yoix is a registered trademark of AT&T Inc.
|