Path: csiph.com!eternal-september.org!feeder.eternal-september.org!reader01.eternal-september.org!.POSTED!not-for-mail
From: Tim Rentsch
Newsgroups: comp.lang.c
Subject: Re: Const-qualified function return type in C - is it a part of function type?
Date: Mon, 24 Feb 2020 21:06:41 -0800
Organization: A noiseless patient Spider
Lines: 66
Message-ID: <867e0bb6hq.fsf@linuxsc.com>
References: <45853431-d208-46e0-8945-78a42ed1a83e@googlegroups.com> <8736b2aeib.fsf@bsb.me.uk> <130f8fed-d0ed-4a1c-affb-475c707103d5@googlegroups.com> <87eeum6jup.fsf@bsb.me.uk>
Mime-Version: 1.0
Content-Type: text/plain; charset=us-ascii
Injection-Info: reader02.eternal-september.org; posting-host="736228d0aa4bff80edfe6f310ec1eb3b"; logging-data="18257"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX18dhFuCOylCVG95NeUtI4CT/XZ0s33/qFk="
User-Agent: Gnus/5.11 (Gnus v5.11) Emacs/22.4 (gnu/linux)
Cancel-Lock: sha1:RqHfU2dgNBYiLSiFXEjsQy9p2Dw= sha1:FeoomTM3R1JlXvd4h4c5RSEwOeo=
Xref: csiph.com comp.lang.c:150213
Ben Bacarisse writes:
> luser droog writes:
>
>> On Saturday, February 22, 2020 at 8:22:18 AM UTC-6, Ben Bacarisse wrote:
>>
>>> Andrey Tarasevich writes:
>>>
>>>
>>>> To avoid any further wastage of time on this irrelevant matter I
>>>> hereby postulate one more time: the above quoted passage refers to
>>>> qualifiers applied to the function type itself (which, BTW, is only
>>>> possible through typedef names).
>>>
>>> And interesting detail, which I can't interpret... In all versions of
>>> the C standard, there is a footnote attached to the paragraph
>>>
>>> "If the specification of an array type includes any type qualifiers,
>>> the element type is so qualified, not the array type. If the
>>> specification of a function type includes any type qualifiers, the
>>> behavior is undefined."
>>>
>>> In C90, this footnote seems to be:
>>>
>>> 59) Both of these can only occur through the use of typedefs.
>>>
>>> By C99 it appears to have become
>>>
>>> 118) Both of these can occur through the use of typedefs.
>>>
>>> Why the change I wonder? Is there a way to qualify a function or array
>>> type without a typedef? I can't see one.
>>
>> What about using parens?
>
> I don't think you can. I tried.
I concur with Ben here.
>> int (const sammy[2]);
>
> I think int (const sammy)[2]; would be closer (were it allowed) because
> parentheses in a declarator are there to stop you reading in the
> "default" direction -- to the right. Reading what you wrote, you'd say
> "sammy is an array of 2 const int".
>
>> float (volatile davis)(void);
>
> That's the way it would be written, but you can't do that as far as I
> can see.
If we are looking for an extension to supply the capability, how
about this way:
int sammy const [2];
float davis volatile (void);
I note with some amusement that C++ made a different choice, for
member functions:
int x_value() const;
Of course the meaning of "const" here isn't quite the same as
the "const" we are used to, but it does modify the function
type itself: they are commonly (or officially?) called
"const member functions".