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


Groups > comp.lang.c > #379417

Re: Inconsistent...

From Ben Bacarisse <ben.usenet@bsb.me.uk>
Newsgroups comp.lang.c
Subject Re: Inconsistent...
Date 2023-10-31 16:15 +0000
Organization A noiseless patient Spider
Message-ID <87fs1qrcns.fsf@bsb.me.uk> (permalink)
References <uhp5jb$kbc1$2@dont-email.me> <uhpdrm$3blvk$1@i2pn2.org> <uhpndq$3c4tj$1@i2pn2.org> <87lebjqb6g.fsf@bsb.me.uk> <uhr28e$3dnb9$1@i2pn2.org>

Show all headers | View raw


bart <bc@freeuk.com> writes:

> [Reposting as the original reply seems to have vanished, but it may
> reappear]
>
> On 31/10/2023 11:32, Ben Bacarisse wrote:
>> bart <bc@freeuk.com> writes:
>>
>>> On 30/10/2023 23:22, bart wrote:
>>>> On 30/10/2023 21:01, Chris M. Thomasson wrote:
>>
>>>> I tweaked the source code (used explicit assignment to fields of some
>>>> structs) to be able to use my compilers.
>>>> Then I tried these compilers:
>>>> gcc 13.2.0 - this worked. (I assume it is supposed to show some
>>>> plaintext, encrypted text starting "fog.IiQ' U'?zDjP))v$oN)?z<xT
>>>> CAPNKUfB...", then the identical plaintext)
>>>> tcc - failed. The encrypted text started
>>>> "xy,$}lu~@NM*a%^z1YA+'N@9yrV]E...", and the decrypted was:
>>>>
>     "dEjtkuXVjq5*uzqpWXE6tkzXVjq5czuqpWXE!t9zX\j35czu30/XE!tkuX\!qocuu3pWXEjtkzXVj3oczuq4WXE!0
>>>> kz.Vjqocuu3p/TEj0ku.Vj31cuz3pWXEjtkzXVj3o*uzq4W."
>>>
>>> Regarding tcc, a few things differ internally, but I think one clue is
>   here:
>>>
>>>     #define CT_MBROT_ABET_LOOKUP(mp_char) \
>>>      ((strchr(CT_MBROT_ABET, (mp_char))) - CT_MBROT_ABET)
>>>
>>> This is effectively doing the following (to get an offset into the
>    string?):
>>>
>>>      str("ABC", c) - "ABC";
>>>
>>> It is assuming that both string literals have the same address.
>>
>> This is an unwarranted assumption.
>>
>> But the result is also undefined when mp_char does not occur in the
>> string which can happen for two printable ASCII characters.
>>
>> Chris, you should test your code more thoroughly.
>>
>>> If I move that string into a variable, then Tcc starts to work. So does
>>> bcc.
>>
>> Saying that tcc starts to work when you fix the bug suggests that tcc
>> was not working before, but it's the code that was not working.  tcc
>> (and presumably bcc) were working fine all along.
>>
>>> lccwin32 still has a problem.
>>
>> What's the problem?  Are you sure it's lccwin32 and not the source code
>> that has the problem?
>
> When I say that compiler X has a problem, obviously I mean that the program
> built with X shows an error.

That's a very odd way of putting it.  My guess is that the
program has multiple meanings (and in some cases none).  The compiler is
(probably) correctly picking one of them. 

> That is, the results are incorrect.

Ah, then you know more that I.  What are the correct results?

> I'm not suggesting the compilers are at fault, although that is a
> possibility especially with bcc (however, see below).
>
> Probably this is not what Chris had in mind when he mentioned
> inconsistency. But finding out why those compilers are producing the wrong
> results I think is a useful first step to find out what is amiss with this
> program.

The compiler is (probably) not producing the wrong results.  The program
is producing results that the author did not intend.

> (Throwing loads of -W options at it with gcc didn't show anything that
> interesting.)

I found the result of carefully chosen -W options to be interesting.
Maybe you should reconsider "throwing" options at the compiler

> And that does appear to a bug with the 64-bit version of lccwin32,
> demonstrated here:
>
>     #include <stdio.h>
>     #include <math.h>
>
>     int main(void) {
>          printf("%f\n", fmod(0.445226, 1.0));
>     }
>
> This produces an output of 'nan', rather than 0.445226.

Better to say that there is a bug in the implementation.  The compiler
might be implementing fmod, but it's likely to be comming from a
library.  I think lccwin32 has it's own library, but it's still not
really "the compiler".

> Given the amount of floating point, I can't say I'm surprised, but I'd be
> interesting in establishing exactly why.

Yes, some of it unnecessary.  For example:

  unsigned long
  cantor_packing(
      unsigned int n0,
      unsigned int n1
  ){
      unsigned long ret = 0.5 * (n0 + n1) * (n0 + n1 + 1) + n1;
   
      return ret;
  }

There is no need for floating point arithmetic here; C's x/2 works fine
when implementing this function.

-- 
Ben.

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