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


Groups > comp.lang.c > #123750

Re: Some kind of contextual modulo operator?

Path csiph.com!fu-berlin.de!uni-berlin.de!individual.net!not-for-mail
From Ian Collins <ian-news@hotmail.com>
Newsgroups comp.lang.c
Subject Re: Some kind of contextual modulo operator?
Date Sun, 3 Dec 2017 16:13:03 +1300
Lines 164
Message-ID <f8h8dvFrrtU8@mid.individual.net> (permalink)
References <e10414e1-e674-4a1c-96e7-39e598cc4dc9@googlegroups.com> <8baec7c1-5c5e-4391-b011-9317ff220752@googlegroups.com> <XNDTB.102542$au1.26875@fx45.am4> <w5ETB.84939$bN1.53680@fx14.am4> <c73af526-10fe-46c3-a98b-ec3345ec9238@googlegroups.com> <DiHTB.65770$7d.19343@fx05.am4> <1679454a-2d88-4821-be92-a73dba4d4d75@googlegroups.com> <jFSTB.60693$1M.45530@fx32.am4> <bfeUB.110929$au1.21996@fx45.am4> <sufUB.3600$bx.564@fx42.iad> <4%fUB.65585$M61.56524@fx38.am4> <lnpo7yw6q0.fsf@kst-u.example.com> <JdkUB.50935$UP1.28649@fx31.am4> <ovuj8g$geq$1@dont-email.me> <ImDUB.111267$W61.42286@fx08.am4> <f8gg0pFrrtU1@mid.individual.net> <0tFUB.85166$sg1.2798@fx43.am4> <f8gn8jFrrtU2@mid.individual.net> <09HUB.67556$7d.15807@fx05.am4> <f8h0c3FrrtU5@mid.individual.net> <W5JUB.130511$xv1.3106@fx21.am4>
Mime-Version 1.0
Content-Type text/plain; charset=utf-8; format=flowed
Content-Transfer-Encoding 8bit
X-Trace individual.net r6AMjbbI//ATUkRtzQu40wn0W0Cpo6ph8knne2Vj+3+NbcQkoN
Cancel-Lock sha1:oEBw1oYtHztVP+I+ug57sL7Qlyw=
User-Agent Mozilla/5.0 (X11; Linux x86_64; rv:52.0) Gecko/20100101 Thunderbird/52.4.0
In-Reply-To <W5JUB.130511$xv1.3106@fx21.am4>
Content-Language en-US
Xref csiph.com comp.lang.c:123750

Show key headers only | View raw


On 12/03/2017 03:14 PM, bartc wrote:
> On 03/12/2017 00:55, Ian Collins wrote:
>> On 12/03/2017 01:01 PM, bartc wrote:
> 
>>> I'm not sure you get it.
>>
>> Oh I'm sure I do.
> 
> I don't think you do.
> 
>>> In C you can do this:
>>>
>>>      #include <I.h>
>>>
>>>      struct T x,y,z;
>>>
>>>      F(&a);
>>>
>>> if you want to make use of function F() in a library, which exports its
>>> interface via a file I.h.
>>>
>>> You don't need to know the details of struct T. You don't need to know
>>> about the other 100 private types that struct T is built on.
>>
>> So why would you be calling a function with a type you don't know what
>> to do with?  That is the point:  whether you are calling from C or
>> another language, you have to know what the type is.  If you don't, why
>> would you be using the function?
> 
> I'm not disputing any of that. But if using C, all that is done for you.
> You have to understand some, but not all, of the types that are used in
> the interface.
> 
> But from another language, the interface has to duplicated, and for
> that, you need an EXACT understanding of ALL the types and subtypes and
> subsubtypes, together with the exact offsets, alignments and padding
> that are used.

The offsets, alignments and padding are the domain of the platform ABI, 
not C.

As for the rest, my point stands.  If you want to avoid resting or 
writing nonsense, you have to know the types, calling from C or not.

>     You are claiming that C interfaces are
>> too complex to use because you have to understand them!
>>
>>>> I'm saying the ABI + understanding what you are doing is all you need.
>>>
>>> How does that help with my example above?
>>
>> It tells you all you need to know.
> 
> Will it translate 20,000 to 200,000 lines of windows.h for me?

I don't do windows, so I cant comment.  You are the one who chooses to 
suffer it...

>>> Yes eventually the job can get done, but it means spending an inordinate
>>> amount of time tracing functions, types and macros in C header files.
>>
>> That's called understanding the function.
> 
> No it's not. People don't look at header files to understand how to use
> functions (and if they spend too long trying to make sense of gcc
> headers, they would go around the bend).

No, they read the man pages or other documentation where they will find 
the declarations of the types being used.

> 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.

>> There isn't anything (except assembler) lower level than C.  If you
>> think that you can design a language which provides libraries of just
>> functions with no types, go ahead.
> 
> You're the one talking about using no types.

I'm not - you say it's the types that make calling C API functions hard. 
I say this will be an issue no matter what the API language is.

> And there have been plenty
> of low level languages, but everyone seems to be obsessed with C even
> though it took until 1999 before you could even tell the language you
> wanted a 16- or 32- or 64-bit number.
> 
> None of those other languages though have become popular.

Quite.  Most of the programming world (modulo you) is happy with C as an 
interface language.  If you don't like a C API, wrap it with a better 
one or do as many well designed libraries do and provide to/from string 
functions to support simple, if slow, calling from other languages.

>>> Except perhaps me; the C I produce is very clean and very clear in
>>> comparison with most I've seen.
>>
>> You need to look further.
> 
> Much further. The MSVC version of struct stat (one of five in
> sys/stat.h) looks like this (for 64-bit):
> 
> struct _stat64 {
>           _dev_t     st_dev;
>           _ino_t     st_ino;
>           unsigned short st_mode;
>           short      st_nlink;
>           short      st_uid;
>           short      st_gid;
>           _dev_t     st_rdev;
>           __int64    st_size;
>           __time64_t st_atime;
>           __time64_t st_mtime;
>           __time64_t st_ctime;
>           };
> 
> Could you recreate the struct just from this without further
> information? No.

If I was familiar with the platform, yes.  I wouldn't have any trouble 
with the Solaris/Illumos version.

> (I can't give you the version from gcc because I can't find it! It's not
> in sys/stat.h anyway.)

That's because gcc is a compiler, not a library.

> Here's a version also in C (requires a some typedefs) as I would write
> it for clarity:
> 
>    struct _stat {      // 48 bytes
>        u32     st_dev;
>        u16     st_ino;
>        u16     st_mode;
>        i16     st_nlink;
>        i16     st_uid;
>        i16     st_gid;
>        u32     st_rdev;
>        u32     st_size;
>        u64     st_atime;
>        u64     st_mtime;
>        u64     st_ctime;
>    };
> 
> 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.

> In my language there is no automatic padding used at all (and in another
> language, there is no need to use the same member names so it can be
> simplified some more).
> 
> If creating a list of field offsets to use in ASM, which version is more
> helpful?

The one that works on the machine...

-- 
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