Sujet : Re: encapsulating directory operations
De : 643-408-1753 (at) *nospam* kylheku.com (Kaz Kylheku)
Groupes : comp.lang.cDate : 23. May 2025, 21:27:37
Autres entêtes
Organisation : A noiseless patient Spider
Message-ID : <20250523132019.763@kylheku.com>
References : 1 2 3 4 5 6 7 8 9 10 11 12 13 14
User-Agent : slrn/pre1.0.4-9 (Linux)
On 2025-05-23, Keith Thompson <Keith.S.Thompson+
u@gmail.com> wrote:
Richard Harnden <richard.harnden@gmail.invalid> writes:
On 22/05/2025 23:32, Keith Thompson wrote:
"Paul Edwards" <mutazilah@gmail.com> writes:
[...]
In one of your library's headers:
extern const char ESCAPE;
In the corresponding *.c file:
const char ESCAPE = ('z' - 'a' == 25 ? '\x1b' : '\x27');
Change the name if you prefer.
>
Wouldn't that be a reserved identifier?
>
Yes, it would. Good catch.
>
(Identifiers starting with E followed by either a digit or an uppercase
letter are reserved; they could be defined as macros in <errno.h>.)
But C99 introduced, for instance "double round(double);".
If you had programs which used that as a file scope identifier
where <float.h> was included, or an external name, you had a clash.
It wasn't previously announced that common mathematical words are
reserved, or that identifiers starting with "r" are reserved.
Basically, the concept of reserved spaces is not worth a damn, because
ISO C doesn't actually confine itself to them when naming new entities,
and so no matter what name you choose, you could have a clash in the
future.
There is no way to estimate whether some specific name starting with E
is more or less likely to experience a clash than any other hame;
i.e. we cannot say with certainty that ESCAPE is more likely to
clash than MY_ESCAPE.
Ironically, one way to protect yourself, at least as a solo developer
working on a greenfield projecg with no third party cruft, is to use
short identifiers like extern const char ES. Because no standard or
major API is going to use short names. Everyone uses long-ish names
because it's insane to do otherwise. And that gives YOU the room
to do the insane thing. :)
-- TXR Programming Language: http://nongnu.org/txrCygnal: Cygwin Native Application Library: http://kylheku.com/cygnalMastodon: @Kazinator@mstdn.ca