Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.c > #379494

Re: Inconsistent...

From Tim Rentsch <tr.17687@z991.linuxsc.com>
Newsgroups comp.lang.c
Subject Re: Inconsistent...
Date 2023-11-09 15:54 -0800
Organization A noiseless patient Spider
Message-ID <86r0kyzdm5.fsf@linuxsc.com> (permalink)
References <uhp5jb$kbc1$2@dont-email.me> <uhuckk$1p9g6$1@dont-email.me> <87ttq5nokm.fsf@bsb.me.uk>

Show all headers | View raw


Ben Bacarisse <ben.usenet@bsb.me.uk> writes:

> Richard Harnden <richard.nospam@gmail.invalid> writes:
>
>> On 30/10/2023 21:01, Chris M. Thomasson wrote:
>>
>>> https://pastebin.com/raw/fcV5YiJH
>>
>> $ gcc -std=c99 -pedantic -W -Wall -fsanitize=undefined -O2 -lm ffe.c

>> ffe.c:305:18: warning: taking the absolute value of unsigned type
>> 'unsigned int' has no effect [-Wabsolute-value]
>>             ec = abs(icount - ec);
>>                  ^
>> ffe.c:305:18: note:  remove the call to 'abs' since unsigned values
>> cannot be negative
>>             ec = abs(icount - ec);
>>                  ^~~
>> 1 warning generated.
>>
>> If you follow that advise, then it doesn't decrypt.
>
> That's "compiler" advice!  While icount - ec is indeed unsigned,
> the conversion to int (the argument type of abs) is sometimes
> undefined due to overflow.

Converting an unsigned int to int is implementation-defined, not
undefined.  (The C standard also allows an implementation-defined
signal to be raised, but it's unlikely either gcc or clang does
so.)

> So removing the call is fine in the eyes of a compiler because the
> result will be the same in the defined cases and compilers don't
> care about the undefined ones.

The compiler is giving stupid advice.  The result is defined in
all cases, except for when the (post-conversion) argument value
happens to be INT_MIN.  Unless the implementation-defined rule
for converting an unsigned int to an int is very strange,
removing the call changes the program's semantics.

Back to comp.lang.c | Previous | NextPrevious in thread | Next in thread | Find similar | Unroll thread


Thread

Inconsistent... "Chris M. Thomasson" <chris.m.thomasson.1@gmail.com> - 2023-10-30 14:01 -0700
  Re: Inconsistent... "Chris M. Thomasson" <chris.m.thomasson.1@gmail.com> - 2023-10-30 14:11 -0700
  Re: Inconsistent... "Chris M. Thomasson" <chris.m.thomasson.1@gmail.com> - 2023-10-30 14:30 -0700
    Re: Inconsistent... Richard Harnden <richard.nospam@gmail.invalid> - 2023-10-30 22:01 +0000
      Re: Inconsistent... "Chris M. Thomasson" <chris.m.thomasson.1@gmail.com> - 2023-10-30 15:09 -0700
  Re: Inconsistent... bart <bc@freeuk.com> - 2023-10-30 23:22 +0000
    Re: Inconsistent... bart <bc@freeuk.com> - 2023-10-30 23:44 +0000
    Re: Inconsistent... bart <bc@freeuk.com> - 2023-10-31 02:05 +0000
      Re: Inconsistent... Ben Bacarisse <ben.usenet@bsb.me.uk> - 2023-10-31 11:32 +0000
        Re: Inconsistent... bart <bc@freeuk.com> - 2023-10-31 14:16 +0000
          Re: Inconsistent... Ben Bacarisse <ben.usenet@bsb.me.uk> - 2023-10-31 16:15 +0000
            Re: Inconsistent... bart <bc@freeuk.com> - 2023-10-31 18:35 +0000
              Re: Inconsistent... "Chris M. Thomasson" <chris.m.thomasson.1@gmail.com> - 2023-10-31 14:05 -0700
                Re: Inconsistent... bart <bc@freeuk.com> - 2023-10-31 22:29 +0000
              Re: Inconsistent... Ben Bacarisse <ben.usenet@bsb.me.uk> - 2023-11-01 00:39 +0000
                Re: Inconsistent... bart <bc@freeuk.com> - 2023-11-01 10:35 +0000
                Re: Inconsistent... Ben Bacarisse <ben.usenet@bsb.me.uk> - 2023-11-01 13:29 +0000
                Re: Inconsistent... "Chris M. Thomasson" <chris.m.thomasson.1@gmail.com> - 2023-11-01 12:52 -0700
                Re: Inconsistent... "Chris M. Thomasson" <chris.m.thomasson.1@gmail.com> - 2023-11-01 14:30 -0700
        Re: Inconsistent... "Chris M. Thomasson" <chris.m.thomasson.1@gmail.com> - 2023-10-31 13:37 -0700
          Re: Inconsistent... Ben Bacarisse <ben.usenet@bsb.me.uk> - 2023-11-01 00:44 +0000
            Re: Inconsistent... "Chris M. Thomasson" <chris.m.thomasson.1@gmail.com> - 2023-10-31 20:26 -0700
              Re: Inconsistent... Ben Bacarisse <ben.usenet@bsb.me.uk> - 2023-11-01 11:05 +0000
            Re: Inconsistent... bart <bc@freeuk.com> - 2023-11-01 10:59 +0000
              Re: Inconsistent... David Brown <david.brown@hesbynett.no> - 2023-11-01 13:01 +0100
                Re: Inconsistent... Ben Bacarisse <ben.usenet@bsb.me.uk> - 2023-11-01 13:52 +0000
                Re: Inconsistent... David Brown <david.brown@hesbynett.no> - 2023-11-01 20:12 +0100
                Re: Inconsistent... "Chris M. Thomasson" <chris.m.thomasson.1@gmail.com> - 2023-11-01 12:52 -0700
                Re: Inconsistent... David Brown <david.brown@hesbynett.no> - 2023-11-02 10:04 +0100
                Re: Inconsistent... "Chris M. Thomasson" <chris.m.thomasson.1@gmail.com> - 2023-11-02 10:51 -0700
                Re: Inconsistent... "Chris M. Thomasson" <chris.m.thomasson.1@gmail.com> - 2023-11-02 11:02 -0700
                Re: Inconsistent... David Brown <david.brown@hesbynett.no> - 2023-11-02 20:02 +0100
                Re: Inconsistent... "Chris M. Thomasson" <chris.m.thomasson.1@gmail.com> - 2023-11-02 12:03 -0700
                Re: Inconsistent... "Chris M. Thomasson" <chris.m.thomasson.1@gmail.com> - 2023-11-03 23:57 -0700
                Re: Inconsistent... "Chris M. Thomasson" <chris.m.thomasson.1@gmail.com> - 2023-11-04 00:11 -0700
                Re: Inconsistent... Ben Bacarisse <ben.usenet@bsb.me.uk> - 2023-11-02 20:28 +0000
                Re: Inconsistent... David Brown <david.brown@hesbynett.no> - 2023-11-03 10:23 +0100
                [OT] Encryption (Was: Inconsistent...) Ben Bacarisse <ben.usenet@bsb.me.uk> - 2023-11-03 10:10 +0000
                Re: [OT] Encryption (Was: Inconsistent...) David Brown <david.brown@hesbynett.no> - 2023-11-03 15:01 +0100
                Re: [OT] Encryption (Was: Inconsistent...) scott@slp53.sl.home (Scott Lurndal) - 2023-11-03 16:52 +0000
                Re: [OT] Encryption (Was: Inconsistent...) "Chris M. Thomasson" <chris.m.thomasson.1@gmail.com> - 2023-11-03 15:12 -0700
                Re: Inconsistent... "Chris M. Thomasson" <chris.m.thomasson.1@gmail.com> - 2023-11-03 15:11 -0700
              Re: Inconsistent... Ben Bacarisse <ben.usenet@bsb.me.uk> - 2023-11-01 13:43 +0000
                Re: Inconsistent... "Chris M. Thomasson" <chris.m.thomasson.1@gmail.com> - 2023-11-01 12:53 -0700
                Re: Inconsistent... Ben Bacarisse <ben.usenet@bsb.me.uk> - 2023-11-01 20:08 +0000
                Re: Inconsistent... "Chris M. Thomasson" <chris.m.thomasson.1@gmail.com> - 2023-11-01 13:12 -0700
                Re: Inconsistent... Ben Bacarisse <ben.usenet@bsb.me.uk> - 2023-11-01 21:12 +0000
                Re: Inconsistent... "Chris M. Thomasson" <chris.m.thomasson.1@gmail.com> - 2023-11-01 14:16 -0700
                Re: Inconsistent... Ben Bacarisse <ben.usenet@bsb.me.uk> - 2023-11-01 21:43 +0000
                Re: Inconsistent... "Chris M. Thomasson" <chris.m.thomasson.1@gmail.com> - 2023-11-01 16:02 -0700
                Re: Inconsistent... bart <bc@freeuk.com> - 2023-11-01 22:59 +0000
  Re: Inconsistent... Ben Bacarisse <ben.usenet@bsb.me.uk> - 2023-10-30 23:52 +0000
    Re: Inconsistent... "Chris M. Thomasson" <chris.m.thomasson.1@gmail.com> - 2023-10-31 13:45 -0700
    Re: Inconsistent... "Chris M. Thomasson" <chris.m.thomasson.1@gmail.com> - 2023-10-31 14:29 -0700
    Re: Inconsistent... David Brown <david.brown@hesbynett.no> - 2023-11-02 10:10 +0100
      Re: Inconsistent... Ben Bacarisse <ben.usenet@bsb.me.uk> - 2023-11-02 09:52 +0000
        Re: Inconsistent... bart <bc@freeuk.com> - 2023-11-02 11:31 +0000
          Re: Inconsistent... David Brown <david.brown@hesbynett.no> - 2023-11-02 13:52 +0100
            Re: Inconsistent... bart <bc@freeuk.com> - 2023-11-02 14:07 +0000
              Re: Inconsistent... David Brown <david.brown@hesbynett.no> - 2023-11-02 16:53 +0100
                Re: Inconsistent... bart <bc@freeuk.com> - 2023-11-02 19:15 +0000
                Re: Inconsistent... David Brown <david.brown@hesbynett.no> - 2023-11-03 10:33 +0100
          Re: Inconsistent... Ben Bacarisse <ben.usenet@bsb.me.uk> - 2023-11-02 20:43 +0000
            Re: Inconsistent... "Chris M. Thomasson" <chris.m.thomasson.1@gmail.com> - 2023-11-02 13:47 -0700
        Re: Inconsistent... David Brown <david.brown@hesbynett.no> - 2023-11-02 13:34 +0100
  Re: Inconsistent... Richard Harnden <richard.nospam@gmail.invalid> - 2023-11-01 20:32 +0000
    Re: Inconsistent... Ben Bacarisse <ben.usenet@bsb.me.uk> - 2023-11-01 21:36 +0000
      Re: Inconsistent... Richard Harnden <richard.nospam@gmail.invalid> - 2023-11-01 21:54 +0000
      Re: Inconsistent... Tim Rentsch <tr.17687@z991.linuxsc.com> - 2023-11-09 15:54 -0800
  Re: Inconsistent... "Chris M. Thomasson" <chris.m.thomasson.1@gmail.com> - 2023-11-09 01:16 -0800
  Re: Inconsistent... "Chris M. Thomasson" <chris.m.thomasson.1@gmail.com> - 2023-11-10 21:02 -0800

csiph-web