Re: Word For Today: “Uglification”

Liste des GroupesRevenir à l c 
Sujet : Re: Word For Today: “Uglification”
De : Keith.S.Thompson+u (at) *nospam* gmail.com (Keith Thompson)
Groupes : comp.lang.c
Date : 13. Mar 2024, 01:00:05
Autres entêtes
Organisation : None to speak of
Message-ID : <878r2n839m.fsf@nosuchdomain.example.com>
References : 1 2 3 4 5 6 7 8 9 10 11 12
User-Agent : Gnus/5.13 (Gnus v5.13) Emacs/27.2 (gnu/linux)
bart <bc@freeuk.com> writes:
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"

Note that malloc.h is not a standard header.

Apparently this helped you find and fix a bug in your compiler.

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.

Yes.  But it doesn't "happen to" find a file called string.h; that file
is part of the project.  You've just explained it correctly, so I'm not
sure what confuses you.

That is undesirable, unless you specifically want to shadow the
standard headers. In the examples I saw, that was not the case.

You didn't mention that.  If you'd tell us what project you're talking
about, maybe we could discuss it.  Perhaps

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!
>
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"
>
With the two headers doing totally different things.

I'm not going to say that programs *should* be allowed to do that, but
the fact is that they *are* allowed to do that.

Read section 6.10.2 of the standard.  It describes the search rules for
the #include directive.

To summarize, #include <foo.h> searches for a header (probably but not
necessarily a file) identified by foo.h.  #include "foo.h" searches for
a *file* called foo.h, and if that fails it then searches for a header
identified by <foo.h>.  The sequences for both searches are
implementation-defined.

(The standard does mention the possibility that the "foo.h" search is
not supported.  Any such implementation would not be able to handle
user-defined header files; perhaps they would have to be installed as
"headers" somehow.  In every implementation I know about, the compiler
will *at least* find the foo.h file if it's in the same directory as the
file that includes it.  And if an implementation is able to handle
#include "foo.h", it can also handle #include "string.h".)

If you provide a file called "string.h" as part of your project, and set
up the implementation-defined search paths correctly, then
    #include "string.h"
refers to the file in your project, and
    #include <string.h>
refers to the standard header.

Having <string.h> and "string.h" do "totally different things" would
perhaps be unwise, but nothing in the standard forbids it.  (I wonder
if you think it could or should.)

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.

No they wouldn't -- or rather, no they don't.  A program that carelessly
uses #include "string.h" to refer to the standard header will work just
fine as long as the project doesn't have a file by that name.  The
initial search will fail, and then it will find the standard header.
Certainly #include <string.h> is better style.  And a program that
deliberately uses #include "string.h" to refer to its own file by that
name, it will work correctly as long as the search path is set up
correctly.

I'm personally not entirely comfortable with mirroring standard header
names, like using #include "string.h" to use a header file that wraps
the standard header <string.h>.  My first thought on seeing that would
be to think that the author should have used <> rather than "".  There's
also some risk that if you don't set up the search path correctly,
#include "string.h" could refer to the standard header.  But I can see
how it would be useful, and nothing in the language forbids it.  If a
project uses such a scheme consistently, I have no problem with it,
beyond a brief moment of "Oh, that's what you're doing".

I might prefer #include "string_wrapper.h".

[snip]

--
Keith Thompson (The_Other_Keith) Keith.S.Thompson+u@gmail.com
Working, but not speaking, for Medtronic
void Void(void) { Void(); } /* The recursive call of the void */

Date Sujet#  Auteur
12 Mar 24 * Word For Today: “Uglification”63Lawrence D'Oliveiro
12 Mar 24 +* Re: Word For Today: “Uglification”3Keith Thompson
12 Mar 24 i`* Re: Word For Today: “Uglification”2Lawrence D'Oliveiro
12 Mar 24 i `- Re: Word For Today: “Uglification”1Keith Thompson
12 Mar 24 +* Re: Word For Today: “Uglification”11Kaz Kylheku
14 Mar 24 i`* Re: Word For Today: “Uglification”10Tim Rentsch
14 Mar 24 i `* Re: Word For Today: “Uglification”9Keith Thompson
15 Mar 24 i  +* Re: Word For Today: “Uglification”2Keith Thompson
15 Mar 24 i  i`- Re: Word For Today: “Uglification”1David Brown
15 Mar 24 i  +* Re: Word For Today: “Uglification”5Keith Thompson
15 Mar 24 i  i`* Re: Word For Today: “Uglification”4Keith Thompson
15 Mar 24 i  i `* Re: Word For Today: “Uglification”3Kaz Kylheku
15 Mar 24 i  i  `* Re: Word For Today: “Uglification”2Keith Thompson
15 Mar 24 i  i   `- Re: Word For Today: “Uglification”1David Brown
15 Mar 24 i  `- Re: Word For Today: “Uglification”1Tim Rentsch
12 Mar 24 +* Re: Word For Today: “Uglification”47James Kuyper
12 Mar 24 i`* Re: Word For Today: “Uglification”46Lawrence D'Oliveiro
12 Mar 24 i +- Re: Word For Today: “Uglification”1Lawrence D'Oliveiro
12 Mar 24 i +* Re: Word For Today: “Uglification”37Kaz Kylheku
12 Mar 24 i i`* Re: Word For Today: “Uglification”36Richard Kettlewell
12 Mar 24 i i +* Re: Word For Today: “Uglification”22David Brown
12 Mar 24 i i i+* Re: Word For Today: “Uglification”20Anton Shepelev
12 Mar 24 i i ii`* Re: Word For Today: “Uglification”19bart
12 Mar 24 i i ii +* Re: Word For Today: “Uglification”17Anton Shepelev
12 Mar 24 i i ii i`* Re: Word For Today: “Uglification”16bart
12 Mar 24 i i ii i `* Re: Word For Today: “Uglification”15Kaz Kylheku
13 Mar 24 i i ii i  `* Re: Word For Today: “Uglification”14bart
13 Mar 24 i i ii i   +* Re: Word For Today: “Uglification”12Keith Thompson
13 Mar 24 i i ii i   i+* Re: Word For Today: “Uglification”10bart
13 Mar 24 i i ii i   ii+* Re: Word For Today: “Uglification”7Michael S
13 Mar 24 i i ii i   iii+* Re: Word For Today: “Uglification”4Keith Thompson
13 Mar 24 i i ii i   iiii`* Re: Word For Today: “Uglification”3David Brown
13 Mar 24 i i ii i   iiii `* Re: Word For Today: “Uglification”2Keith Thompson
13 Mar 24 i i ii i   iiii  `- Re: Word For Today: “Uglification”1David Brown
13 Mar 24 i i ii i   iii+- Re: Word For Today: “Uglification”1David Brown
13 Mar 24 i i ii i   iii`- Re: Word For Today: “Uglification”1Kaz Kylheku
13 Mar 24 i i ii i   ii`* Re: Word For Today: “Uglification”2Keith Thompson
13 Mar 24 i i ii i   ii `- Re: Word For Today: “Uglification”1bart
13 Mar 24 i i ii i   i`- Re: Word For Today: “Uglification”1Nick Bowler
13 Mar 24 i i ii i   `- Re: Word For Today: “Uglification”1Kaz Kylheku
12 Mar 24 i i ii `- Re: Word For Today: “Uglification”1Kaz Kylheku
13 Mar 24 i i i`- Re: Word For Today: “Uglification”1Blue-Maned_Hawk
13 Mar 24 i i `* Re: Word For Today: “Uglification”13Lawrence D'Oliveiro
13 Mar 24 i i  +* Re: Word For Today: “Uglification”11Keith Thompson
13 Mar 24 i i  i`* Re: Word For Today: “Uglification”10Richard Kettlewell
13 Mar 24 i i  i `* Re: Word For Today: “Uglification”9Keith Thompson
13 Mar 24 i i  i  +* Re: Word For Today: “Uglification”7Lawrence D'Oliveiro
14 Mar 24 i i  i  i+- Re: Word For Today: “Uglification”1Kaz Kylheku
14 Mar 24 i i  i  i+- Re: Word For Today: “Uglification”1Keith Thompson
14 Mar 24 i i  i  i`* Re: Word For Today: “Uglification”4Lawrence D'Oliveiro
14 Mar 24 i i  i  i `* Re: Word For Today: “Uglification”3Keith Thompson
14 Mar 24 i i  i  i  +- Re: Word For Today: “Uglification”1Richard Kettlewell
14 Mar 24 i i  i  i  `- Re: Word For Today: “Uglification”1Kaz Kylheku
19 Jun 24 i i  i  `- Re: Word For Today: “Uglification”1Tim Rentsch
13 Mar 24 i i  `- Re: Word For Today: “Uglification”1Kaz Kylheku
12 Mar 24 i `* Re: Word For Today: “Uglification”7James Kuyper
12 Mar 24 i  `* Re: Word For Today: “Uglification”6Lawrence D'Oliveiro
13 Mar 24 i   +- Re: Word For Today: “Uglification”1Keith Thompson
13 Mar 24 i   `* Re: Word For Today: “Uglification”4James Kuyper
13 Mar 24 i    `* Re: Word For Today: “Uglification”3Lawrence D'Oliveiro
14 Mar 24 i     +- Re: Word For Today: “Uglification”1Kaz Kylheku
14 Mar 24 i     `- Re: Word For Today: “Uglification”1James Kuyper
12 Mar 24 `- Re: Word For Today: “Uglification”1Kaz Kylheku

Haut de la page

Les messages affichés proviennent d'usenet.

NewsPortal