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


Groups > comp.lang.c > #107996

Re: LLVM and Forth

From Ben Bacarisse <ben.usenet@bsb.me.uk>
Newsgroups comp.lang.forth, comp.lang.c
Subject Re: LLVM and Forth
Date 2017-04-10 16:18 +0100
Organization A noiseless patient Spider
Message-ID <87h91ws345.fsf@bsb.me.uk> (permalink)
References (9 earlier) <s4wFA.637264$3a3.286206@fx43.am4> <2017Apr9.165301@mips.complang.tuwien.ac.at> <xuAGA.661090$nT1.467590@fx44.am4> <ocerfl$5j4$1@dont-email.me> <HsLGA.931050$vF2.237690@fx46.am4>

Cross-posted to 2 groups.

Show all headers | View raw


Spiros Bousbouras <spibou@gmail.com> writes:

> On Sun, 9 Apr 2017 22:46:04 -0400
> James Kuyper <jameskuyper@verizon.net> wrote:
>> On 04/09/2017 08:38 PM, Spiros Bousbouras wrote:
>> > [ Crossposted to  comp.lang.c  since we need some C lawyers ;-) ]
>> > 
>> > On Sun, 09 Apr 2017 14:53:01 GMT
>> > anton@mips.complang.tuwien.ac.at (Anton Ertl) wrote:
>
> [...]
>
>> > Before you go to the C standards committee you need to have a specific proposal. I
>> > take it that for C to be a suitable back end for implementing Forth , you want
>> > comparison of C pointers pointing to different objects to be defined. Could you
>> 
>> Note: C++ requires that std::less<T*> must provide a total ordering of
>> all pointers of type T*, even if the "<" operator does not provide such
>> an ordering (20.9.5p14). C++ has a sufficiently strong shared heritage
>> with C that the fact that the C++ standard can successfully impose this
>> requirement strongly suggests that the C standard could impose a similar
>> requirement.
>> However, it's telling that C++ did NOT impose this requirement on the
>> "<" operator itself, but only on std::less<T*>. That's because there are
>> some systems where meeting this requirement makes std::less<T*>(p,q)
>> substantially slower than p<q.
>
> I wonder if for Anton's purposes and for a big endian machine the following
> would do
>
> int compare_pointers_to_void(void **p1 , void **p2) {
>     return memcmp(*p1 , *p2 , sizeof(void *)) ;
> }

That seems unlikely.  You might have meant

  int compare_pointers_to_void(void **p1, void **p2) {
      return memcmp(p1, p2, sizeof (void *));
  }

or, possibly,

  int compare_pointers_to_void(void *p1, void *p2) {
      return memcmp(&p1, &p2, sizeof (void *));
  }

Note that using the idiom:

  memcmp(<exp1>, <exp2>, sizeof *<exp1>);

can highlight indirection issues like this.  Your example written in
this style is

  int compare_pointers_to_void(void **p1, void **p2) {
      return memcmp(*p1, *p2, sizeof **p1);
  }

and sizeof **p1 is sizeof a void object -- undefined.

But even fixed, I doubt that comparing the representation of the
pointers is a good idea.  If the system uses some peculiar segmented
architecture, that's going to go wrong.  Even though it's not portable,
the best solution is usually to convert to an integer type.  Where that
is meaningful, C99 implementations provide the type uintptr_t in
stdint.h.

<snip>
-- 
Ben.

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


Thread

Re: LLVM and Forth Spiros Bousbouras <spibou@gmail.com> - 2017-04-10 00:38 +0000
  Re: LLVM and Forth James Kuyper <jameskuyper@verizon.net> - 2017-04-09 22:46 -0400
    Re: LLVM and Forth Robert Wessel <robertwessel2@yahoo.com> - 2017-04-09 22:27 -0500
    Re: LLVM and Forth Spiros Bousbouras <spibou@gmail.com> - 2017-04-10 12:36 +0000
      Re: LLVM and Forth Ben Bacarisse <ben.usenet@bsb.me.uk> - 2017-04-10 14:09 +0100
    Re: LLVM and Forth Spiros Bousbouras <spibou@gmail.com> - 2017-04-10 13:07 +0000
      Re: LLVM and Forth Ben Bacarisse <ben.usenet@bsb.me.uk> - 2017-04-10 16:18 +0100
      Re: LLVM and Forth "James R. Kuyper" <jameskuyper@verizon.net> - 2017-04-10 11:51 -0400
        Re: LLVM and Forth Spiros Bousbouras <spibou@gmail.com> - 2017-04-12 21:32 +0000
          Re: LLVM and Forth "James R. Kuyper" <jameskuyper@verizon.net> - 2017-04-12 18:29 -0400
          Re: LLVM and Forth supercat@casperkitty.com - 2017-04-12 15:34 -0700
            Re: LLVM and Forth Spiros Bousbouras <spibou@gmail.com> - 2017-04-12 23:41 +0000
          Re: LLVM and Forth albert@cherry.spenarnc.xs4all.nl (Albert van der Horst) - 2017-04-13 02:55 +0200
  Re: LLVM and Forth supercat@casperkitty.com - 2017-04-10 15:12 -0700
    Re: LLVM and Forth Spiros Bousbouras <spibou@gmail.com> - 2017-04-12 23:34 +0000
      Re: LLVM and Forth supercat@casperkitty.com - 2017-04-12 17:25 -0700
        Re: LLVM and Forth Keith Thompson <kst-u@mib.org> - 2017-04-12 20:04 -0700

csiph-web