Sujet : Re: constexpr keyword is unnecessary
De : 643-408-1753 (at) *nospam* kylheku.com (Kaz Kylheku)
Groupes : comp.lang.cDate : 29. Oct 2024, 06:04:35
Autres entêtes
Organisation : A noiseless patient Spider
Message-ID : <20241028215919.996@kylheku.com>
References : 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
User-Agent : slrn/pre1.0.4-9 (Linux)
On 2024-10-28, Thiago Adams <
thiago.adams@gmail.com> wrote:
I believe warnings in code should be treated as alarms that require
acknowledgment.
>
For instance,
>
const unsigned char ch = 1234;
>
GCC:
warning: unsigned conversion from 'int' to 'unsigned char' changes value
from '1234' to '210' [-Woverflow]
>
The programmer might intend this behavior; in that case, the "alarm"
should be acknowledged.
>
I would like a portable (standardized) way to achieve this.
For conversion warnings, that portable way should ideally be a cast.
Any half-decent compiler should shut up if the conversion is
explicitly requested:
const unsigned char ch = (unsigned char) 1234;
If not, complain to the compiler developer.
It works this way for conversions that are constraint violations,
like between unlike pointers. Assign a pointer to a variable of
the wrong type, and there is a required diagnostic. With a cast,
the diagnostic is not required, and it would be irksome if there
still were one.
-- TXR Programming Language: http://nongnu.org/txrCygnal: Cygwin Native Application Library: http://kylheku.com/cygnalMastodon: @Kazinator@mstdn.ca