1

I was just reading C11, 7.1.3 Reserved identifiers, 2, which says:

No other identifiers are reserved.

Here is a quick test:

# gcc on Linux
$ echo -e "#include <time.h>\n#define CLK_TCK" | gcc82 -xc - -std=c11 -pedantic -Wall -Wextra -E > /dev/null
<stdin>:2: warning: "CLK_TCK" redefined
In file included from /usr/local/ossf/glibc-2.25/include/time.h:33,
                 from <stdin>:1:
/usr/local/ossf/glibc-2.25/include/bits/time.h:41: note: this is the location of the previous definition
 # define CLK_TCK ((__clock_t) __sysconf (2)) /* 2 is _SC_CLK_TCK */

# gcc on Windows (Cygwin):
$ echo -e "#include <limits.h>\n#define NL_NMAX" | gcc -xc - -std=c11 -pedantic -Wall -Wextra -E > /dev/null
<stdin>:2: warning: "NL_NMAX" redefined
In file included from /usr/lib/gcc/x86_64-pc-cygwin/11/include/limits.h:203,
                 from /usr/lib/gcc/x86_64-pc-cygwin/11/include/syslimits.h:7,
                 from /usr/lib/gcc/x86_64-pc-cygwin/11/include/limits.h:34,
                 from <stdin>:1:
/usr/include/limits.h:507: note: this is the location of the previous definition
  507 | #define NL_NMAX                              INT_MAX

# msvc
$ echo -e "#include <errno.h>\n#define STRUNCATE" > tmp.c && cl tmp.c /std:c11 /Za
tmp.c(2): warning C4005: 'STRUNCATE': macro redefinition
C:\Program Files (x86)\Windows Kits\10\include\10.0.20313.0\ucrt\errno.h(81): note: see previous definition of 'STRUNCATE'

The CLK_TCK, NL_NMAX, STRUNCATE, etc. are expected to be available to the end user. Or do I miss something?

Is it acceptable practice to reserve CLK_TCK, NL_NMAX, STRUNCATE, etc.?

pmor
  • 5,392
  • 4
  • 17
  • 36
  • 2
    This is kind of a duplicate: https://stackoverflow.com/a/69734163/584518. As mentioned there, no it is not ok and not compliant. – Lundin Nov 04 '21 at 12:08
  • 2
    Re “… considered acceptable practice?”: It has been that way for a while, and many people have not rejected it. I.e., they accept it. Therefore, it is *de facto* acceptable practice. Bad, non-conforming, but accepted. – Eric Postpischil Nov 04 '21 at 12:33
  • @EricPostpischil Thanks! Interesting. I didn't know that. Also: `#undef` cannot be used because the user's definition may appear before `#include`. These identifiers are expected to be `_` prefixed. – pmor Nov 09 '21 at 23:28
  • @EricPostpischil Re: non-conforming. It turns out that implementations do claim conformance, which may be false in the reality. However, such false conformance turns out to be non-critical in many cases. I think that implementations can claim conformance _w.r.t. tests they were using_. Example: "we pass all the Perennial tests, hence we do conform". What is your view? – pmor Nov 09 '21 at 23:36
  • @EricPostpischil FYI: C2x relaxed the requirement from "No other identifiers are reserved" (C11) to "No other potentially reserved identifiers are reserved" (C2x). I see it as "not potentially reserved identifiers may be reserved". – pmor Nov 10 '21 at 11:12
  • @pmor: If an implementation can correctly process at least one program (possibly a contrived and useless one) that exercises the translation limits given in N1570 5.2.4.1, nothing it does with any other source text will render it non-conforming. Per the Rationale, "While a deficient implementation could probably contrive a program that meets this requirement, yet still succeed in being useless, the C89 Committee felt that such ingenuity would probably require more work than making something useful." – supercat Nov 24 '21 at 22:53

0 Answers0