[Aldor-l] Compiling setup
Gabriel Dos Reis
gdr at integrable-solutions.net
Sun Aug 13 09:44:22 EDT 2006
"Christian Aistleitner" <tmgisi at gmx.at> writes:
| Hello,
|
| On Sun, 13 Aug 2006 02:02:25 +0200, Gabriel Dos Reis
| <gdr at integrable-solutions.net> wrote:
|
| > Ralf Hemmecke <ralf at hemmecke.de> writes:
| >
| > | > | local a:String == "abc";
| > | > | In the second it would be quite questionable.
| > | ... what the value of a is after assignment
| > | a.3 := char "X";
| >
| > Stephen gave me an explanation and if I did understand correctly, that
| > assignment is also OK.
|
| sadly enough, this seems to have been a private discussion and has not
| been posted to aldor-l -- Or did I miss it?
You're correct that it was a private message. He just reminded me
that since a is defined as
a : String == "abc";
therefore with type String, and a String is modifiable, the
modification
a.3 := char "X"
is OK.
| > [...]
| >
| > | Just being curious... is there a legal C program that defines a
| > | constant array, and a pointer (or whatever) to on element of that
| > | array and then modifies that entry in-place?
| >
| > If I understand the question correctly, the answer is "no".
|
| For those being not familiar with C or C++:
| These languages also provide a modifier const (just doing what its
| name suggests), which Aldor (currently) lacks.
OK, let me expand a little bit on this.
First of all, K&R lacks "const" -- it was an invention for "C with
Classes" (the precursor of C++) that the ANSI C committee adopted
later, sadly with a slightly different semantics. However, given
char *a = "hqdfnoioffe";
you can't modify what a points to -- though you're free to modify the
pointer a. Notice that no const is involved there.
The reason is that in C, therefore in C++, modifiability really is a
*property of the object*, not just that of the expression used to
access the object. However, you are right that C++ does enforce those
properties more often than C by lifting most of them directly into the
static semantics. For example the string literal
"hqdfnoioffe"
has type
const char[12]
in C++. The proper way to write the above declaration in C++ is
const char *a = "hqdfnoioffe";
However, the declaration
char *a = "hqdfnoioffe";
is also accepted for C-compatibility reasons, but deprecated. The
semantics however remains that you can't modify what a points to.
-- Gaby
More information about the Aldor-l
mailing list