Path: csiph.com!fu-berlin.de!uni-berlin.de!individual.net!not-for-mail From: Ian Collins Newsgroups: comp.lang.c Subject: Re: Some kind of contextual modulo operator? Date: Sun, 3 Dec 2017 14:50:18 +1300 Lines: 67 Message-ID: References: <8baec7c1-5c5e-4391-b011-9317ff220752@googlegroups.com> <1679454a-2d88-4821-be92-a73dba4d4d75@googlegroups.com> <4%fUB.65585$M61.56524@fx38.am4> <0tFUB.85166$sg1.2798@fx43.am4> <09HUB.67556$7d.15807@fx05.am4> Mime-Version: 1.0 Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 8bit X-Trace: individual.net L+rqCN3OGoQqi9DyOfjyFgSv0gJ6WLMjXfVomTTvJ0/n6mHpPQ Cancel-Lock: sha1:ENpehcGJ55IAGAhihAbdO7Ej0gU= User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:52.0) Gecko/20100101 Thunderbird/52.4.0 In-Reply-To: <09HUB.67556$7d.15807@fx05.am4> Content-Language: en-US Xref: csiph.com comp.lang.c:123746 On 12/03/2017 01:01 PM, bartc wrote: > On 02/12/2017 22:20, Ian Collins wrote: >> On 12/03/2017 11:06 AM, bartc wrote: >>> On 02/12/2017 20:16, Ian Collins wrote: >>>> On 12/03/2017 08:42 AM, bartc wrote: >>>>> On 02/12/2017 16:09, David Brown wrote: >>>>> >>>>>> But C function calls are as easy as it gets. >>>>> >>>>> And apparently you DO think that! The docs for a typical C function are >>>>> for the benefit of someone wanting to use the function FROM C. Any >>>>> other >>>>> information essential for using that function from elsewhere is not >>>>> included. >>>> >>>> The platform ABI tells you all you need to know. >>> >>> About what, the call convention? Which on 32-bit Windows is variable >>> anyway. >>> >>> It doesn't say anything about types that C code has invented and where >>> the definitions rely on compiling a bunch of C header code. >>> >>> Take this function from SDL: >>> >>> extern DECLSPEC int SDLCALL SDL_SetWindowModalFor(SDL_Window * >>> modal_window, SDL_Window * parent_window); >>> >>> If you're calling it from C, then it's straightforward: you include the >>> requisite headers, define the appropriate variables of the right types, >>> and call. >>> >>>   From another language however, you can't do that: you have to >>> painstakingly track down the definitions of each type (and usually they >>> will be structs consisting of a bunch of other types). You need to >>> establish the layout and alignment of those structs so as to create >>> exact duplicates. And if you're unlucky, there will be a mess of >>> conditional code so that even that is not clear. >> >> So in C you can happily call something without understanding it, > > I'm not sure you get it. > > In C you can do this: > > #include > > 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. > > But now try and call F() from language X. You can't just do the above, > but need to duplicate the interface described in I.h. This case is where C interfaces work well - you just use an opaque type such as FILE*. No one cares what a FILE is, you never manipulate it directly. -- Ian.