Tim Rentsch <tr.17687@z991.linuxsc.com> writes:
Keith Thompson <Keith.S.Thompson+u@gmail.com> writes:
The more C is changed to resemble C++ the worse it becomes. It
isn't surprising that you like it.
For context, since the parent article is from a month and a half
ago, I was discussing a proposal to change a future C standard to
refer to "constants" as "literals". I mentioned that I think it's
a good idea.
On 28.09.2024 05:34, Keith Thompson wrote:
Tim Rentsch <tr.17687@z991.linuxsc.com> writes:
Keith Thompson <Keith.S.Thompson+u@gmail.com> writes:
The more C is changed to resemble C++ the worse it becomes. It
isn't surprising that you like it.
For context, since the parent article is from a month and a half
ago, I was discussing a proposal to change a future C standard to
refer to "constants" as "literals". I mentioned that I think it's
a good idea.
I've heard of and seen various forms to name such entities...
- in a Pascal and an Eiffel book I find all these named "constants"
- in an Algol 68 book I read about "standard designations"
- in a book about languages and programming in general I find
"literals" ("abc"), "numerals" (42), "word-symbols" (false),
"graphemes" (©), etc., differentiated
- I've also have heard about "standard representations [for the
values of a respective type]"; also a type-independent term
I also think (for various reasons) that "constants" is not a good
term. (Personally I like terms like the Algol 68 term, that seems
to "operate" on another [more conceptual] abstraction level.)
But you'll certainly have to expect a lot of anger if the terminology
of some standards documents get changed from one version to another.
Janis
In reply to "Janis Papanagnou" who wrote the following:[...]
I also think (for various reasons) that "constants" is not a good
term. (Personally I like terms like the Algol 68 term, that seems
to "operate" on another [more conceptual] abstraction level.)
But you'll certainly have to expect a lot of anger if the terminology
of some standards documents get changed from one version to another.
The only gripe I would have if we synonymized constants and literals
is that not every const is initialized with a literal. There have been
times where I have initialized a const from the value of a variable. I
don't think that const and literals are the same thing because of
this.
Phillip Frabott <nntp@fulltermprivacy.com> writes:
In reply to "Janis Papanagnou" who wrote the following:[...]
I also think (for various reasons) that "constants" is not a good
term. (Personally I like terms like the Algol 68 term, that seems
to "operate" on another [more conceptual] abstraction level.)
But you'll certainly have to expect a lot of anger if the terminology
of some standards documents get changed from one version to another.
The only gripe I would have if we synonymized constants and literals
is that not every const is initialized with a literal. There have been times where I have initialized a const from the value of a variable. I don't think that const and literals are the same thing because of
this.
Though the word "const" is obviously derived from the English word "constant", in C "const" and "constant" are very different things.
The "const" keyword really means "read-only" (and perhaps would have
been clearer if it had been spelled "readonly").
A "constant" is what some languages call a "literal", and a "constant expression" is an expression that can be evaluated at compile time.
For example, this:
const int r = rand();
is perfectly valid.
In reply to "Keith Thompson" who wrote the following:
Phillip Frabott <nntp@fulltermprivacy.com> writes:
In reply to "Janis Papanagnou" who wrote the following:[...]
I also think (for various reasons) that "constants" is not a good
term. (Personally I like terms like the Algol 68 term, that seems
to "operate" on another [more conceptual] abstraction level.)
But you'll certainly have to expect a lot of anger if the terminology
of some standards documents get changed from one version to another.
The only gripe I would have if we synonymized constants and literals
is that not every const is initialized with a literal. There have been
times where I have initialized a const from the value of a variable. I
don't think that const and literals are the same thing because of
this.
Though the word "const" is obviously derived from the English word
"constant", in C "const" and "constant" are very different things.
The "const" keyword really means "read-only" (and perhaps would have
been clearer if it had been spelled "readonly").
In the context of C I agree. Although I would point out that for some langauges
const and readonly are two completely different things. (just a brevity remark,
but I'll get back on topic now)
A "constant" is what some languages call a "literal", and a "constant
expression" is an expression that can be evaluated at compile time.
For example, this:
const int r = rand();
is perfectly valid.
Maybe the expression can be determined/evaluated at compile time but not the result. When I think of literals the resulting value has to be determined at compile time. So const int r = 15; would be to me a literal result. The compiler
can bake that in without needing further runtime execution to get such result.
But a const can be either a literal or non-literal in my view. Anything that cannot give a predetermined value at compile time is a const. So to me:
const int r = rand();
is not a literal only because the output of rand() is unknown until
runtime.
From a human-readable code perspective I get it. And fine, there can be a similarity between const and literal on the surface. But the moment you need to
know exactly what the compiler is doing, those two things have to be separate.
Sysop: | DaiTengu |
---|---|
Location: | Appleton, WI |
Users: | 991 |
Nodes: | 10 (0 / 10) |
Uptime: | 119:23:43 |
Calls: | 12,958 |
Files: | 186,574 |
Messages: | 3,265,634 |