[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [RFC] struct field initialization and implicit constraints
From: |
Jose E. Marchesi |
Subject: |
Re: [RFC] struct field initialization and implicit constraints |
Date: |
Sat, 17 Apr 2021 20:41:26 +0200 |
User-agent: |
Gnus/5.13 (Gnus v5.13) Emacs/28.0.50 (gnu/linux) |
>> Hi Dan.
>>
>>> I know I'm a bit late to the party since you already pushed the changes,
>>> but here are my 2cts anyway ;-)
>>
>> Nah, until we release, we can always change it :)
>> Thanks for the feedback.
>>
>>> "Jose E. Marchesi" <jemarch@gnu.org> writes:
>>>
>>>> a) Do nothing, and document the workaround in 1).
>>>>
>>>> b) Add a new syntax like `:= VALUE' to mean initialization-only, and
>>>> keep the current semantics of `= VALUE'.
>>>>
>>>> c) Change the semantics of `= VALUE' to mean initialization-only, and
>>>> add a new syntax like `== VALUE' to always mean
>>>> initialization-and-implicit-constraint.
>>>>
>>>> In this case, using `== VALUE' would forbid to also specify an
>>>> explicit constraint, i.e. this would not be permitted:
>>>>
>>>> type Foo =
>>>> struct
>>>> {
>>>> uint<16> magic == 0xfeef : magic > 0; /* error */
>>>> [...]
>>>> };
>>>>
>>>> My preference at this point is c).
>>>> Opinions?
>>>
>>> I must admit that I do not like c) too much, as it looks like a
>>> comparison to me. I'd suggest to use either b) or maybe add something
>>> like a decorator?
>>
>> Well, it _is_ a comparison... it implies both a comparison and an
>> initialization.
>
> Let me rephrase it: when I see:
> val == 0xdeadbeef : val > 1
But that is not a valid construct. When you use the == notation you are
not allowed to specify an additional constraint expression.
It is the initialization-only = notation that lets you specify an
optional additional constraint expression, like in:
val = 0xdeadbeef : val > 1;