Path: csiph.com!eternal-september.org!reader02.eternal-september.org!.POSTED!not-for-mail From: Keith Thompson Newsgroups: comp.lang.c Subject: Re: Why does C allow structs to have a tag? Date: Wed, 28 Jul 2021 16:07:28 -0700 Organization: None to speak of Lines: 63 Message-ID: <87zgu6f367.fsf@nosuchdomain.example.com> References: <867dijb22a.fsf@linuxsc.com> <86a6mt8g69.fsf@linuxsc.com> <20210727083246.384@kylheku.com> <87h7gfiqu0.fsf@nosuchdomain.example.com> <87sfzzgr72.fsf@nosuchdomain.example.com> <1mgMI.17475$6j.16299@fx04.iad> Mime-Version: 1.0 Content-Type: text/plain Injection-Info: reader02.eternal-september.org; posting-host="f7dbd806dd1436700e4487cff600874e"; logging-data="21638"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX19nchYn2F+ap8KclclnS1XU" User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/27.2 (gnu/linux) Cancel-Lock: sha1:6xdQwzgMYYKLvzc56N2PQQNWfvA= sha1:UnXnzBjLDm2JBXgpGnNSK9/x39U= Xref: csiph.com comp.lang.c:162083 Bart writes: > On 28/07/2021 18:21, Scott Lurndal wrote: >> Bart writes: [...] > I want to call a C function via an FFI from a language that I've > devised. The public API says one parameter type is off_t. > > Which type matches that in my language? I have to choose from i8-i64 > and u8-u64. > > The kind of answer I want is (a) 'It uses i64' etc; or (b) 'It uses > i32 or u64 depending on platform'. POSIX says that off_t is a signed integer type. Is there some reason that compiling and running this program on the target system doesn't solve your problem? #include #include int main(void) { printf("off_t is %c%zu\n", (off_t)-1 < (off_t)0 ? 'i' : 'u', CHAR_BIT * sizeof (off_t)); } > Not keeping the answer buried for decades under a dozen typedefs, > dependent on a dozen conditional macros, dependent on the C compilers > used [what C compiler? I might not have one] and hidden in include > files 6 levels deep, scattered across multiple directories, to make it > as hard as possible to find out. Yeah, you don't need to do any of that. [...] >>> This is exactly my point. A compiler installation can exist for just one >>> platform. This goes for Windows compilers such as Pelles C (2 targets), >>> DMC, lccwin (2 targets), Tcc (2 targets). >> So what? Programmers generally[*] don't write code for a >> particular compiler or platform, >> they write code to the language specification to solve some problem, which is independent >> of any particular compiler implementation. Portability of C code is what >> has built the internet as we know it. >> And for other languages, the language provides the binding, for >> example: >> http://www.nongnu.org/posix90/#SEC7 > > This doesn't do struct stat. But supposing it did, how did /they/ pick > up the necessary information? Although they seem to have clocked that > 'clock_t' is an integer type, rather than float, something else that C > prefers to keep under wraps. POSIX says that clock_t can be either integer or floating-point. You can use a method similar to what I wrote above to find out what it is in a particular implementation (without reading the header files). -- Keith Thompson (The_Other_Keith) Keith.S.Thompson+u@gmail.com Working, but not speaking, for Philips void Void(void) { Void(); } /* The recursive call of the void */