Sujet : Re: Word For Today: “Uglification”
De : 433-929-6894 (at) *nospam* kylheku.com (Kaz Kylheku)
Groupes : comp.lang.cDate : 12. Mar 2024, 19:50:14
Autres entêtes
Organisation : A noiseless patient Spider
Message-ID : <20240312114213.182@kylheku.com>
References : 1 2 3 4 5 6 7 8 9 10
User-Agent : slrn/pre1.0.4-9 (Linux)
On 2024-03-12, bart <
bc@freeuk.com> wrote:
On 12/03/2024 15:09, Anton Shepelev wrote:
bart:
Anton Shepelev:
David Brown:
>
The limited support for avoiding name clashes in C
(user-level C, outside of the implementation
internals) is certainly something that he (or others)
/could/ complain about. It is a well-known issue, and
it's a shame that the C standards committee have never
dealt with it. I don't see why the language could not
adopt a simple "namespace" solution that would hugely
simplify avoiding identifier clashes. (It wouldn't
help for macros, but we have inline functions to
handle many cases.)
>
My hypothetical solution is to have a single function
returning a struct with pointers to all the public
functions of a module.
>
What stops that function name clashing with the single
function exported from other people's modules?
A much lower probability.
>
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.
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?
There is no such rule that when you name a "whatever.h", you must
ensure there does not exist a <whatever.h>.
People like reusing the same popular module names so much, they will
even use the names of standard headers!
Sometimes deliberately so. Why did I call that header "termios.h"
is that the module is relates to is related to the POSIX termios;
the source file is called termios.c and includes <termios.h> as
well as its own "termios.h". This makes things readable; someone
looking at the directory listing can guess that these files
constitute a module which wraps termios.
Any other naming would obscure that to some degree, other than
perhaps longer names that contain "termios" as a substring.
-- TXR Programming Language: http://nongnu.org/txrCygnal: Cygwin Native Application Library: http://kylheku.com/cygnalMastodon: @Kazinator@mstdn.ca