Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
| From | Kaz Kylheku <864-117-4973@kylheku.com> |
|---|---|
| Newsgroups | comp.std.c |
| Subject | Re: What is the point of restrict in fopen? |
| Date | 2023-07-25 19:33 +0000 |
| Organization | A noiseless patient Spider |
| Message-ID | <20230725120541.589@kylheku.com> (permalink) |
| References | <20230524162836.172@kylheku.com> <86cz0mzemm.fsf@linuxsc.com> <9x2cnQDaqOkRtyf5nZ2dnZeNn_di4p2d@giganews.com> <20230721215906.639@kylheku.com> <86lef4rwx9.fsf@linuxsc.com> |
On 2023-07-25, Tim Rentsch <tr.17687@z991.linuxsc.com> wrote:
> Kaz Kylheku <864-117-4973@kylheku.com> writes:
>
>> On 2023-07-21, Jakob Bohm <jb-usenet@wisemo.com.invalid> wrote:
>>
>>> On 2023-07-20 19:17, Tim Rentsch wrote:
>>>
>>>> Kaz Kylheku <864-117-4973@kylheku.com> writes:
>>>>
>>>>> I've noticed that both arguments of fopen are restrict-qualified.
>>>>
>>>> What I think you mean is that the arguments given in the prototype
>>>> declaration in the C standard are qualified with the 'restrict'
>>>> keyword.
>>>>
>>>> Note that this form of declaration has no effect on the semantics
>>>> of the function. The function declaration, and its semantics, are
>>>> just the same as if the uses of 'restrict' were removed.
>>>
>>> Note that Tim's critique or restrict in May 2023 is very similar
>>> to the critique of the similar noalias proposal in messageid
>>> <7753@alice.UUCP> by someone highly respected in this group.
>>> That was posted 35 years ago.
>>
>> That someone was even opposed to const, for some good reasons.
>>
>> The present issue reveals a design flaw in the C type system:
>> that qualifiers on function parameters don't matter.
>>
>> They should, though.
>>
>> void f(const int);
>> void f(int);
>>
>> should be incomaptible and diagnosed!
>
> A foolish consistency is the hobgoblin of little minds.
I deserve that for starting with that silly bait,
but I later acknowledged that the flexibility is necessary
to be able to const-qualify a parameter in the definition
without touching the declaration.
Here is a realistic plan.
Phase 1:
Qualifiers except restrict are ignored in function
declarators, are not part of the function type and do not
participate in composition. The restrict qualifier is now
part of the type. If a declaration restrict-qualifies a parameter, a
redeclaration (or definition) need not. The composite type of the
parameter will be restrict-qualified.
Tolerance for the presence of const and volatile qualifiers on
paramaters in prototype declarations is marked obsolescent.
Phase 2:
The obsolescence period introduced in Phasae 1 ends. Const and volatile
qualifiers are no longer allowed on parameters in declarations; it is a
diagnosable constraint violation. They are allowed in definitions only,
and don't contribute to the function type declared.
A new obsolescence period begins: situations in which multiple
declarations of a function differ in the restrict-qualification of a
parameter are considered obsolescent.
Phase 3:
Obsolescence period from Phase 2 ends: it is a constraint violation
whenever a declaration or definition of a function differs
from a previous declaration in the restrict qualification of
a parameter.
// Phase 1 Phase 2 Phase 3
void f(const int); // obsol. error error
//
void f(char *restrict p); //
void g(char *); //
//
void f(char *p) { } // obsol. error
void g(char *restrict p) // obsol. error
i.e. the language becomes sane. Bullshit code smells like qualifiers
that do nothing become errors. If restrict is used to optimize a
function in a way that affects the interface contract, that must be
reflected in the declaration; it is not possible to use restrict
in a definition, but omit that in a declaration.
Back to comp.std.c | Previous | Next — Previous in thread | Next in thread | Find similar
What is the point of restrict in fopen? Kaz Kylheku <864-117-4973@kylheku.com> - 2023-05-24 23:41 +0000
Re: What is the point of restrict in fopen? Tim Rentsch <tr.17687@z991.linuxsc.com> - 2023-07-20 10:17 -0700
Re: What is the point of restrict in fopen? Jakob Bohm <jb-usenet@wisemo.com.invalid> - 2023-07-21 08:55 +0200
Re: What is the point of restrict in fopen? Kaz Kylheku <864-117-4973@kylheku.com> - 2023-07-22 05:37 +0000
Re: What is the point of restrict in fopen? Tim Rentsch <tr.17687@z991.linuxsc.com> - 2023-07-25 05:35 -0700
Re: What is the point of restrict in fopen? Kaz Kylheku <864-117-4973@kylheku.com> - 2023-07-25 19:33 +0000
Re: What is the point of restrict in fopen? Tim Rentsch <tr.17687@z991.linuxsc.com> - 2023-08-04 20:15 -0700
Re: What is the point of restrict in fopen? Tim Rentsch <tr.17687@z991.linuxsc.com> - 2023-07-25 05:37 -0700
csiph-web