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


Groups > comp.lang.c > #123778

Re: Some kind of contextual modulo operator?

From Ian Collins <ian-news@hotmail.com>
Newsgroups comp.lang.c
Subject Re: Some kind of contextual modulo operator?
Date 2017-12-04 10:38 +1300
Message-ID <f8j972FrrtU9@mid.individual.net> (permalink)
References (18 earlier) <09HUB.67556$7d.15807@fx05.am4> <f8h0c3FrrtU5@mid.individual.net> <W5JUB.130511$xv1.3106@fx21.am4> <f8h8dvFrrtU8@mid.individual.net> <T5SUB.122141$pS7.119111@fx41.am4>

Show all headers | View raw


On 12/04/2017 01:28 AM, bartc wrote:
> On 03/12/2017 03:13, Ian Collins wrote:
>> On 12/03/2017 03:14 PM, bartc wrote:
> 
>>> You don't seem to appreciate the difference between the knowledge needed
>>> to use an existing interface, and what is involved in re-implementing
>>> that same interface in a different language.
>>
>> I do, I've already answered that and you snipped it.
> 
> No you haven't. You keep saying knowing the platform ABI is enough. And
> knowing how to use the library is enough. And I keep saying it isn't.

I did, I said that I have written native interface wrappers for PHP if 
you care to look back on the thread.

> Calling any C library function from your own language is always going to
> be a hard slog. And one reason is that the docs are written only with C
> in mind, and they assuming you merely have to write:

It isn't a hard slog.  It requires some thought, but what aspect of 
programming doesn't?  For example what aspect of calling the C standard 
file I/O is a hard slog?

>     #include <I.h>
> 
> so that they don't have to go into, to them, all the unimportant
> details. Because the /C/ compiler will do that job.

The compiler is no substitute for the programmer's brain.  If you need 
to decompose a struct and the output of <insert your compiler of choice 
here> -E is too verbose or your IDE can't tell you, write a small 
program.  It will take trivial time and you only ever have to do it once.

> But we don't have a C compiler, remember? And if we did, we're using
> language X, remember that? A C compiler is of little help.

It can be a bit help if you use it to mine some data for you.

> I don't know if you're being deliberately obtuse or just winding me up.

I'm repeating my own experience.

>> Quite.  Most of the programming world (modulo you) is happy with C as an
>> interface language.
> 
> Well, it's the only one where at least I have a fighting chance. Any
> other language, I might as well pack up and go home (C++ for example).

Yet you still complain..

>> If you don't like a C API, wrap it with a better
>> one
> 
> That means writing C code and having a dependency on a C compiler and C
> build system. Don't forget we want to write C out of the picture.

Do we?

> (My own C compiler can't be used for that because it doesn't, for
> example, have a complete windows.h. Imagine that, even converting an
> interface specified in C, into an interface specified in C, is a
> nightmare using C! In what other language is that possible?)

No compiler has a windows.h, windows does.  The reset of the above is 
just nonsense.  If for example your other language just needs the size 
and modification time of a file, crate a struct with two members laid 
out how you want it, write a wrapper for stat() an populate your struct. 
  Trivial.

>> or do as many well designed libraries do and provide to/from string
>> functions to support simple, if slow, calling from other languages.
> 
> That doesn't solve the problem. Calling functions and/or creating
> suitable structs is not the problem. It's obtaining the information to
> do so that is the problem.

So you keep saying and that has nothing what so ever to do with the 
language!!!

>>> All that's needed to be able to port this another language, is a
>>> knowledge of what alignment and padding is needed. In C this can be done
>>> with '#pragma pack(1)'.
>>
>> No, it can't.  Not all machines support misaligned access.
> 
> Using pack(1) does not mean fields are misaligned. It means that no
> padding is added between fields.

Which means a uint32_t following a uint8_t will be misaligned!  As you 
love Windows, I'll quote MSDN for you:

"To pack a class is to place its members directly after each other in 
memory, which can mean that some or all members can be aligned on a 
boundary smaller than the default alignment the target architecture."

Clear?


> Neither will work because you're not using a C compiler, remember? We're
> just trying to extract the information we need, remember?

We can read code, remember?  We can write code to decipher code, remember?

> Here's another struct (BTW it's not C and it doesn't pad elements):
> 
>     Struct {
>         _abc_t a
>         _def_t b,c
>         _ghi_t d
>     } T;
> 
> And here's how I would write it, in the same language:
> 
>     Struct {         # 16 bytes
>         int32  a
>         uint16 b,c
>         byte   d[8]
>     } T;
> 
> This is the ONLY piece of information you have. Neither will compile on
> your machine because you don't have an implementation of that language.
> 
> You need to duplicate that struct outside of that language.
> 
> OBVIOUSLY the second example is considerably more useful because it uses
> only primitive types for the elements and it is very easy to extract the
> information needed.
> 
> Equally obviously, you are never going to admit I have a point and so
> are going to evade the question yet again.

I haven't evaded anything.  you keep building mountains out of mole 
hills.  C has been a common interface language for decades.  Hundreds of 
C libraries have been wrapped and used by other languages.  The world 
hasn't ended.

> Here's an actual struct example from many years ago, expressed in my
> language, which I had to extract from a 20KB C struct with hundreds of
> complicated fields:
> 
> type jpeg_properties=record
>       [19966]byte  padding             !skip complicated jpeg stuff
>       int16        jfif_app0_units     !19966
>       int16        jfif_app0_xdensity  !19968
>       int16        jfif_app0_ydensity  !19970
>       ichar        jpeg_comment        !19972 [32-bit pointer]
>       int32        jpeg_comment_size   !19976
>       int32        padding2            !19980, total size 19984
> end
> 
> It involved writing example C to figure out all the information I
> needed. Because it was too difficult otherwise to try and recreate all
> the processes of a C compiler in my head to get all the offsets right.
> 
> Without a C compiler - forget it.

I think you have just remade my point: use your tools.

-- 
Ian.

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


Thread

Some kind of contextual modulo operator? "Rick C. Hodgin" <rick.c.hodgin@gmail.com> - 2017-11-29 10:41 -0800
  Re: Some kind of contextual modulo operator? jameskuyper@verizon.net - 2017-11-29 11:12 -0800
    Re: Some kind of contextual modulo operator? bartc <bc@freeuk.com> - 2017-11-29 19:22 +0000
      Re: Some kind of contextual modulo operator? bartc <bc@freeuk.com> - 2017-11-29 19:43 +0000
        Re: Some kind of contextual modulo operator? jameskuyper@verizon.net - 2017-11-29 12:33 -0800
          Re: Some kind of contextual modulo operator? bartc <bc@freeuk.com> - 2017-11-29 23:22 +0000
            Re: Some kind of contextual modulo operator? jameskuyper@verizon.net - 2017-11-29 20:53 -0800
              Re: Some kind of contextual modulo operator? bartc <bc@freeuk.com> - 2017-11-30 12:17 +0000
                Re: Some kind of contextual modulo operator? bartc <bc@freeuk.com> - 2017-12-01 15:08 +0000
                Re: Some kind of contextual modulo operator? "Rick C. Hodgin" <rick.c.hodgin@gmail.com> - 2017-12-01 07:31 -0800
                Re: Some kind of contextual modulo operator? scott@slp53.sl.home (Scott Lurndal) - 2017-12-01 16:32 +0000
                Re: Some kind of contextual modulo operator? bartc <bc@freeuk.com> - 2017-12-01 17:07 +0000
                Re: Some kind of contextual modulo operator? "Rick C. Hodgin" <rick.c.hodgin@gmail.com> - 2017-12-01 09:15 -0800
                Re: Some kind of contextual modulo operator? scott@slp53.sl.home (Scott Lurndal) - 2017-12-01 18:14 +0000
                Re: Some kind of contextual modulo operator? bartc <bc@freeuk.com> - 2017-12-01 19:03 +0000
                Re: Some kind of contextual modulo operator? scott@slp53.sl.home (Scott Lurndal) - 2017-12-01 20:54 +0000
                Re: Some kind of contextual modulo operator? Keith Thompson <kst-u@mib.org> - 2017-12-01 12:09 -0800
                Re: Some kind of contextual modulo operator? bartc <bc@freeuk.com> - 2017-12-01 21:56 +0000
                Re: Some kind of contextual modulo operator? bartc <bc@freeuk.com> - 2017-12-01 23:11 +0000
                Re: Some kind of contextual modulo operator? supercat@casperkitty.com - 2017-12-01 15:16 -0800
                Re: Some kind of contextual modulo operator? David Brown <david.brown@hesbynett.no> - 2017-12-02 17:09 +0100
                Re: Some kind of contextual modulo operator? bartc <bc@freeuk.com> - 2017-12-02 19:42 +0000
                Re: Some kind of contextual modulo operator? Ian Collins <ian-news@hotmail.com> - 2017-12-03 09:16 +1300
                Re: Some kind of contextual modulo operator? bartc <bc@freeuk.com> - 2017-12-02 22:06 +0000
                Re: Some kind of contextual modulo operator? Ian Collins <ian-news@hotmail.com> - 2017-12-03 11:20 +1300
                Re: Some kind of contextual modulo operator? bartc <bc@freeuk.com> - 2017-12-03 00:01 +0000
                Re: Some kind of contextual modulo operator? Ian Collins <ian-news@hotmail.com> - 2017-12-03 13:55 +1300
                Re: Some kind of contextual modulo operator? bartc <bc@freeuk.com> - 2017-12-03 02:14 +0000
                Re: Some kind of contextual modulo operator? Ian Collins <ian-news@hotmail.com> - 2017-12-03 16:13 +1300
                Re: Some kind of contextual modulo operator? bartc <bc@freeuk.com> - 2017-12-03 12:28 +0000
                Re: Some kind of contextual modulo operator? bartc <bc@freeuk.com> - 2017-12-03 14:26 +0000
                Re: Some kind of contextual modulo operator? Ian Collins <ian-news@hotmail.com> - 2017-12-04 10:49 +1300
                Re: Some kind of contextual modulo operator? Ian Collins <ian-news@hotmail.com> - 2017-12-04 10:38 +1300
                Re: Some kind of contextual modulo operator? bartc <bc@freeuk.com> - 2017-12-03 23:00 +0000
                Re: Some kind of contextual modulo operator? Ian Collins <ian-news@hotmail.com> - 2017-12-04 12:10 +1300
                Re: Some kind of contextual modulo operator? bartc <bc@freeuk.com> - 2017-12-03 23:33 +0000
                Re: Some kind of contextual modulo operator? Ian Collins <ian-news@hotmail.com> - 2017-12-04 13:18 +1300
                Re: Some kind of contextual modulo operator? bartc <bc@freeuk.com> - 2017-12-04 12:19 +0000
                Re: Some kind of contextual modulo operator? Ian Collins <ian-news@hotmail.com> - 2017-12-05 07:58 +1300
                Re: Some kind of contextual modulo operator? David Brown <david.brown@hesbynett.no> - 2017-12-04 00:30 +0100
                Packed structs (was Re: Some kind of contextual modulo operator?) scott@slp53.sl.home (Scott Lurndal) - 2017-12-04 15:02 +0000
                Re: Packed structs (was Re: Some kind of contextual modulo operator?) David Brown <david.brown@hesbynett.no> - 2017-12-04 16:34 +0100
                Re: Packed structs (was Re: Some kind of contextual modulo operator?) Keith Thompson <kst-u@mib.org> - 2017-12-04 09:23 -0800
                Re: Packed structs (was Re: Some kind of contextual modulo operator?) scott@slp53.sl.home (Scott Lurndal) - 2017-12-04 18:31 +0000
                Re: Packed structs (was Re: Some kind of contextual modulo operator?) supercat@casperkitty.com - 2017-12-04 15:37 -0800
                Re: Some kind of contextual modulo operator? supercat@casperkitty.com - 2017-12-04 08:39 -0800
                Re: Some kind of contextual modulo operator? "Chris M. Thomasson" <invalid_chris_thomasson@invalid.invalid> - 2017-12-03 18:13 -0800
                Re: Some kind of contextual modulo operator? Ian Collins <ian-news@hotmail.com> - 2017-12-03 14:50 +1300
                Re: Some kind of contextual modulo operator? scott@slp53.sl.home (Scott Lurndal) - 2017-12-04 15:00 +0000
                Re: Some kind of contextual modulo operator? bartc <bc@freeuk.com> - 2017-12-04 15:53 +0000
                Re: Some kind of contextual modulo operator? scott@slp53.sl.home (Scott Lurndal) - 2017-12-04 18:26 +0000
                Re: Some kind of contextual modulo operator? "Rick C. Hodgin" <rick.c.hodgin@gmail.com> - 2017-12-04 10:34 -0800
                Re: Some kind of contextual modulo operator? David Brown <david.brown@hesbynett.no> - 2017-12-03 19:40 +0100
                Re: Some kind of contextual modulo operator? David Kleinecke <dkleinecke@gmail.com> - 2017-12-03 11:35 -0800
                Re: Some kind of contextual modulo operator? scott@slp53.sl.home (Scott Lurndal) - 2017-12-04 14:59 +0000
                Re: Some kind of contextual modulo operator? Keith Thompson <kst-u@mib.org> - 2017-12-01 08:56 -0800
                Re: Some kind of contextual modulo operator? "Rick C. Hodgin" <rick.c.hodgin@gmail.com> - 2017-12-01 08:58 -0800
                Re: Some kind of contextual modulo operator? scott@slp53.sl.home (Scott Lurndal) - 2017-12-01 18:16 +0000
                Re: Some kind of contextual modulo operator? "Rick C. Hodgin" <rick.c.hodgin@gmail.com> - 2017-12-01 10:28 -0800
                Re: Some kind of contextual modulo operator? David Brown <david.brown@hesbynett.no> - 2017-12-01 20:19 +0100
                Re: Some kind of contextual modulo operator? Gareth Owen <gwowen@gmail.com> - 2017-12-01 22:22 +0000
                Re: Some kind of contextual modulo operator? jameskuyper@verizon.net - 2017-12-01 07:49 -0800
                Re: Some kind of contextual modulo operator? bartc <bc@freeuk.com> - 2017-12-01 16:54 +0000
                Re: Some kind of contextual modulo operator? jameskuyper@verizon.net - 2017-12-01 09:34 -0800
                Re: Some kind of contextual modulo operator? bartc <bc@freeuk.com> - 2017-12-01 18:48 +0000
                Re: Some kind of contextual modulo operator? jameskuyper@verizon.net - 2017-12-01 11:27 -0800
      Re: Some kind of contextual modulo operator? "Rick C. Hodgin" <rick.c.hodgin@gmail.com> - 2017-11-29 12:17 -0800
        Re: Some kind of contextual modulo operator? bartc <bc@freeuk.com> - 2017-11-30 12:27 +0000
          Re: Some kind of contextual modulo operator? "Rick C. Hodgin" <rick.c.hodgin@gmail.com> - 2017-11-30 06:11 -0800
    Re: Some kind of contextual modulo operator? "James R. Kuyper" <jameskuyper@verizon.net> - 2017-11-29 15:02 -0500
  Some kind of contextual modulo operator? mcheung63@gmail.com - 2017-12-08 23:20 -0800

csiph-web