Martin Wells <> writes:
> Keith Thompson:
>> > char NumToDigit(unsigned const x)
>>
>> I assume this was supposed to be 'unsigned int x'.
>
> No, I meant what I wrote. I'm curious as to why you would've thought
> that. . ? Anyway, to explain why I wrote it that way:
>
> 1: I invariably use "unsigned" as an abbreviation of "unsigned int".
> 2: I pretty much use const wherever possible.
That was partly a failure on my part to understand what you wrote.
The "unsigned const x" threw me off enough that I momentarily forgot
that "unsigned" is synomymous with "unsigned int". (I probably would
have written "const unsigned int" myself.)
"const" in a parameter declaration doesn't do anything useful for the
caller, since (as I'm sure you know) a function can't modify an
argument anyway. It does prevent the function from (directly)
modifying its own parameter (a local object), but that's of no concern
to the caller.
It would make more sense to be able to specify "const" in the
*definition* of a function but not in the *declaration*. And gcc
seems to allow this:
int foo(int x);
int main(void)
{
return foo(0);
}
int foo(const int x)
{
return x;
}
but I'm not sure whether it's actually legal. In any case, it's not a
style that seems to be common.
I'm sympathetic to the idea uf using const whenever possible.
<OT>If I ever design my own language, declared objects will be
constant (i.e., read-only) by default; if you want to be able to
modify an object, you'll need an extra keyword ('var'?) on the
declaration.</OT>
[...]
> With the whole "cast to suppress warning" thing, we're relying more on
> industry common practice than anything inherent in the C language or
> its standard.
>
> Still though, I advocate its usage.
Fair enough. I don't.
--
Keith Thompson (The_Other_Keith)
kst- <http://www.ghoti.net/~kst>
San Diego Supercomputer Center <*> <http://users.sdsc.edu/~kst>
"We must do something. This is something. Therefore, we must do this."
-- Antony Jay and Jonathan Lynn, "Yes Minister"