Deutsch English Français Italiano |
<20240312172439.206@kylheku.com> View for Bookmarking (what is this?) Look up another Usenet article |
Path: ...!npeer.as286.net!npeer-ng0.as286.net!3.eu.feeder.erje.net!feeder.erje.net!eternal-september.org!feeder3.eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail From: Kaz Kylheku <433-929-6894@kylheku.com> Newsgroups: comp.lang.c Subject: Re: Word For Today: =?UTF-8?Q?=E2=80=9CUglification=E2=80=9D?= Date: Wed, 13 Mar 2024 02:53:26 -0000 (UTC) Organization: A noiseless patient Spider Lines: 97 Message-ID: <20240312172439.206@kylheku.com> References: <uso6or$3t3jn$3@dont-email.me> <usopec$4eob$1@dont-email.me> <usort1$4t2r$1@dont-email.me> <20240312003531.349@kylheku.com> <wwvwmq7x4ex.fsf@LkoBDZeT.terraraq.uk> <usp9m5$7it7$1@dont-email.me> <20240312174600.5b88613545da9f667e06a4c6@g{oogle}mail.com> <uspqa4$bfao$1@dont-email.me> <20240312180904.ac3a5856df424c396689db3e@g{oogle}mail.com> <uspt5n$c2bg$1@dont-email.me> <20240312114213.182@kylheku.com> <usql0p$hk2k$1@dont-email.me> Injection-Date: Wed, 13 Mar 2024 02:53:26 -0000 (UTC) Injection-Info: dont-email.me; posting-host="1e487003ba0b33508276944d7fda6b3a"; logging-data="676002"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX19bv1VdJEo9RWlmN0CFazEcl14j5vDNTko=" User-Agent: slrn/pre1.0.4-9 (Linux) Cancel-Lock: sha1:NqL3+49uIJKy3FKEiuoir+k4V5M= Bytes: 4978 On 2024-03-12, bart <bc@freeuk.com> wrote: > On 12/03/2024 18:50, Kaz Kylheku wrote: >> On 2024-03-12, bart <bc@freeuk.com> wrote: > > >>> I tried my C compiler with a couple of open source projects recently >>> that both failed for the same mysterious reason. >>> >>> It turned out that one of them used this line: >>> >>> #include "string.h" >>> >>> and the other used: >>> >>> #include "malloc.h" >> >> In the TXR project, I have a "signal.h" header, which must not resolve >> to <signal.h>. I also have "time.h" and "termios.h", "glob.h", >> "regex.h", "alloca.h". >> >> Choosing header names that are distinct from an implementation's >> headers is: >> >> 1) unnecessary due the local-first search strategy of #include "..." >> >> 2) a fool's errand. > > It's confusing. So "string.h" means the standard header, so it is the > same as <string.h>, unless it happens to find a file called string.h > amongst the project files. It's not confusing at all. In projects under my control, you would never see #include "string.h" where the intent is to include <string.h>. It is a lousy practice. > That is undesirable, unless you specifically want to shadow the standard > headers. In the examples I saw, that was not the case. You cannot shadow the standard headers when they are correctly included using #include <...>, unless you resort to compiler specific tricks, like reconfiguring the <...> search to look in a specified directory. > > >> Regarding (2), no name that you choose is guaranteed not to be identical >> to something in the implementation! Suppose I panic and rename >> my "time.h" to "foo.h". Who is to say that some implementation doesn't >> have a <foo.h> header? > > The C implementation? Surely that will list all the system headers that > it provides; it looks quite easy to avoid a clash! But there is no clash to avoid. A local header file that accidentally has the same name as something in your /usr/include or whatever is no problem at all, if you refer to it using #include "...". But if there were a clash to be avoided, it would be tricky. Not all headers are documented, so you would have to actually go looking into the header file installation. The information there is no reliable for portability, because all you learn is what files are present in that installation. >> There is no such rule that when you name a "whatever.h", you must >> ensure there does not exist a <whatever.h>. > > You mean that programs should be allowed to do this: > > #include <string.h> > #include "string.h" No I mean, that programs /are/. > With the two headers doing totally different things. > > I can guess the reasons why such a rule doesn't exist, because so many > programs just carelessly used "..." instead of <...>, and they would all > break if it was imposed. Those programs don't break, because if "string.h" doesn't exist, then it is re-tried as if it were <string.h> (effectively). (I don't think it's the best design; it would be better if "..." and <...> looked in separate places with no fallback from one to the other, such that #include "stdio.h" programs not referencing a local file would break.) > So, is that /your/ file termios.c, or the one that implements the POSIX > termios code? Since my project isn't an operating system, or library for one, but a dynamic language runtime, it has to be the former. -- TXR Programming Language: http://nongnu.org/txr Cygnal: Cygwin Native Application Library: http://kylheku.com/cygnal Mastodon: @Kazinator@mstdn.ca