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: Fri, 30 Jul 2021 14:43:22 -0700 Organization: None to speak of Lines: 104 Message-ID: <87mtq3cwat.fsf@nosuchdomain.example.com> References: <87sfzzgr72.fsf@nosuchdomain.example.com> <1mgMI.17475$6j.16299@fx04.iad> <87zgu6f367.fsf@nosuchdomain.example.com> <87v94tg8sw.fsf@nosuchdomain.example.com> <87mtq5f92k.fsf@nosuchdomain.example.com> <20210730075445.167@kylheku.com> <878s1neknd.fsf@nosuchdomain.example.com> Mime-Version: 1.0 Content-Type: text/plain Injection-Info: reader02.eternal-september.org; posting-host="a2365495de71cceec5c7a6c9f6767045"; logging-data="15915"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX19bf2c1SDw2EQVLiFE7Ql1x" User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/27.2 (gnu/linux) Cancel-Lock: sha1:nPi9PLIKlON8l+SSf/LIzk/qLxQ= sha1:EJAOvVAvMGrdHQtQEvg++x97f+U= Xref: csiph.com comp.lang.c:162144 Bart writes: > On 30/07/2021 19:12, Keith Thompson wrote: >> Bart writes: >> [...] >>> OK. But gcc and tcc are products that you expect to make the necessary >>> arrangements for ensuring they your program can call a C standard >>> function called "printf". >> No, they are not. They are components that can be combined with >> other >> components to create a C implementation. Getting that right is the >> responsibility of whoever puts together the implementation. >> You've written compilers, so you should know all this stuff. >> If someone puts together an implementation that uses gcc as its >> compiler >> and the obsolete MSVCRT.DLL as its runtime library, the result is a >> non-conforming implementation. > > Well, /I/ didn't tell gcc which runtime to choose. Or is that now my > responsibility? Whose responsibility do you think it is? You installed gcc on your Windows system *somehow*. The gcc project itself does not provide installers for Windows. You installed something from some third party, and that installer is responsible for coordinating the various components of the implementation, of which the compiler is just one. If you're satisfied with the way your system is working now, then neither you nor anyone else is responsible for changing it. An implementation that didn't support "%zu" would be a problem *for me*. If I were using such an implementation, I would look for ways to fix or replace it. You will of course do what you want. A great deal of this thread started when you said you wanted to avoid "%zu", and I went out of my way not to ask why. (Admittedly I was being a bit snarky.) I nevertheless have a better understanding now of why you want to avoid "%zu", and I'm not quite sure why we're still talking about it. > I now know that mine will default to Windows' msvcrt.dll unless I > specifically tell it to use libucrt.a. Why the default isn't the other > way around is not something I'm surprised at any more; there are much > worse defaults, and more dangerous. You realize that has to do with C implementations on Windows, not with C the language. >> My experience with Windows C implementations is fairly narrow, but I get >> the impression that most Windows C programmers don't need to worry about >> "%zu" because they use implementations that support it. If it's a >> widespread problem (which is possible), I haven't heard about it other >> than from you. > > Download tcc, which is now a well-respected C99 implementation, and > blazingly fast, and let me know if it supports "zu" out-of-the-box, > and if not, whether there is a way to make it do so. I might try installing tcc on Windows later. Of course whether it supports "%zu" or not depends on what runtime library implementation it's configured to use. I see the web site has several zip files. I see that at least one of them has some references to msvcrt, but I don't know the details. > If you're on Windows, try this: > > * Download the program: > > https://github.com/sal55/langs/blob/master/qq.exe (about 640KB) No, I'm not going to download and run a binary executable from some random GitHub repo. [snip] > I'd be interested in whether any Windows executable produced by your > gcc also imports msvcrt.dll, which looks like this using my dump > program: [snip] On Unix/Linux systems, the "ldd" command shows a list of the shared objects that an executable depends on. The version that runs on Cygwin does the same thing, and shows a list of DLLs. Here's what I get when I compile a simple "hello" program using the default gcc on Cygwin (yes, I'm aware that this is likely not to be typical of how a non-Cygwin gcc installation would work): $ gcc hello.c -o hello.exe $ file hello.exe hello.exe: PE32+ executable (console) x86-64, for MS Windows $ ldd hello.exe ntdll.dll => /cygdrive/c/WINDOWS/SYSTEM32/ntdll.dll (0x7ffe5db80000) KERNEL32.DLL => /cygdrive/c/WINDOWS/System32/KERNEL32.DLL (0x7ffe5c2c0000) KERNELBASE.dll => /cygdrive/c/WINDOWS/System32/KERNELBASE.dll (0x7ffe5b8a0000) cygwin1.dll => /usr/bin/cygwin1.dll (0x180040000) $ Nothing I've tried gives me an executable that refers to msvcrt.dll. -- 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 */