Tim Rentsch <tr.17687@z991.linuxsc.com> wrote:
James Kuyper <jameskuyper@alumni.caltech.edu> writes:
...
Note: in C2023, the [predefined macro names] section says: "Any other
predefined macro names: shall begin with a leading underscore
followed by an uppercase letter; or, a second underscore...". For
earlier versions of the standard, user code should avoid using such
identifiers because they were reserved for all purposes, but that's no
longer the case. Now, they should be avoided because they may be
pre-defined by the implementation, which means that any attempt to use
them might have unpredictable results.
That's right in the sense that if the implementation is unknown then
unexpected results may occur. However, if the implementation is
known, then we can find out what results are expected by consulting
the implementation's documentation for extensions, since any such
macro name must qualify as an extension, and so much be documented.
J.5 identifies as extensions only "... predefined macros with names that
do not begin with an underscore." (J.5, J.5.13)
They are not identified as implementation-defined, so there is no
obligation to document them.
Tim Rentsch <tr.17687@z991.linuxsc.com> writes:
James Kuyper <jameskuyper@alumni.caltech.edu> writes:
[...]
Note: in C2023, the [predefined macro names] section says: "Any other
predefined macro names: shall begin with a leading underscore
followed by an uppercase letter; or, a second underscore...". For
earlier versions of the standard, user code should avoid using such
identifiers because they were reserved for all purposes, but that's no
longer the case. Now, they should be avoided because they may be
pre-defined by the implementation, which means that any attempt to use
them might have unpredictable results.
That's right in the sense that if the implementation is unknown then
unexpected results may occur. However, if the implementation is
known, then we can find out what results are expected by consulting
the implementation's documentation for extensions, since any such
macro name must qualify as an extension, and so much be documented.
Note by the way that the description in N3220 section 6.10.10.1
paragraph 2 makes using #define or #undef be undefined behavior only
for macro names in the subclause (and also a short list of other
identifiers). Hence any other predefined macro name may be used,
definedly, simply by using #undef and then #define for the macro
name in question (in particular, under C23 rules, but not earlier
versions of the C standard).
I don't *think* that all implementation-specific predefined macros have
to be documented -- at least, I'd be surprised if that were the intent.
For example, I don't think an implementation is required to document its
use of _STDIO_H (the include guard header in the glibc implementation of <stdio.h>).
Though it's not normative, N3220 J.5.1 (Common extensions) says:
Examples of such extensions are new keywords, extra library
functions declared in standard headers, or predefined macros with
names that do not begin with an underscore.
Tim Rentsch <tr.17687@z991.linuxsc.com> writes:
antispam@fricas.org (Waldek Hebisch) writes:
Tim Rentsch <tr.17687@z991.linuxsc.com> wrote:
James Kuyper <jameskuyper@alumni.caltech.edu> writes:
[...]
Note: in C2023, the [predefined macro names] section says: "Any
other predefined macro names: shall begin with a leading
underscore followed by an uppercase letter; or, a second
underscore...". For earlier versions of the standard, user code
should avoid using such identifiers because they were reserved
for all purposes, but that's no longer the case. Now, they
should be avoided because they may be pre-defined by the
implementation, which means that any attempt to use them might
have unpredictable results.
That's right in the sense that if the implementation is unknown
then unexpected results may occur. However, if the
implementation is known, then we can find out what results are
expected by consulting the implementation's documentation for
extensions, since any such macro name must qualify as an
extension, and so much be documented.
Hmm, looking at '/usr/include/string.h' on my machine I see
definitions of things like
__GLIBC_INTERNAL_STARTING_HEADER_IMPLEMENTATION
__need_size_t
and lot of similar things. I do not recall seeing any user
documentation listing them. Does this mean that gcc+glibc
is noncompilant in this aspect?
I think it's reasonable to say that the appearance of a macro
name being #define'd in a standard header qualifies as
documenting the name being #define'd.
I disagree. I don't think it's reasonable to say that.
Headers are not documentation. They're often barely human-readable,
and the system headers aren't necessarily even files.
As long as the #define is
readable in an ordinary source file, there isn't any mystery
about the name being used or what its definition is.
System headers can be arbitrarily complex, with #includes for other system-specific headers, nests of #ifs and #ifdefs, and so on.
I suppose
that to satisfy the letter of the C standard, the accompanying
document would need to incorporate the system header files by
reference, but surely the header files satisfy the spirit of
providing the required documentation. Implementation-defined
values for things like CHAR_BIT and INT_MAX fall under the same
rule for documentation as do extensions, yet as far as I know
these values are defined only in system header files, and not in
any separate document.
gcc's documentation does have a "C Implementation-Defined Behavior"
section. It doesn't mention CHAR_BIT by name, but it does document
"The number of bits in a byte" as "Determined by ABI". I didn't
find anything similar for INT_MAX.
I find it implausible that the standard intended to require
implementations to document all macros defined in standard headers,
| Sysop: | Jacob Catayoc |
|---|---|
| Location: | Pasay City, Metro Manila, Philippines |
| Users: | 5 |
| Nodes: | 4 (0 / 4) |
| Uptime: | 25:31:03 |
| Calls: | 117 |
| Calls today: | 117 |
| Files: | 368 |
| D/L today: |
561 files (257M bytes) |
| Messages: | 70,948 |
| Posted today: | 26 |