On 2024-10-28, Thiago Adams 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/txr
Cygnal: Cygwin Native Application Library: http://kylheku.com/cygnal
Mastodon: @Kazinator@mstdn.ca
|
|