Martin Vejnar wrote:
> Flash Gordon wrote:
>> wrote:
>>> that is a header file can be set up in the following lines
>>>
>>> /*things.h*/
>>>
>>> #ifndef _THINGS__H_
>>> #define _THINGS_H_
>>> /*rest of include file*/
>>> #endif
>>
>>
>> People may do this, but it is definitely and categorically WRONG. All
>> identifiers starting with an underscore followed by an upper case
>> letter are reserved for the implementation. You should not ever use
>> them unless you are using some implementation specific extension and
>> the documentation for your implementation EXPLICITLY tells you to use
>> one, and then you should only use it as your implementation says and
>> reallise that the code is completely non-portable.
>
> I agree that using underscore at the beginning of anything is a bad
> idea. But I think that the Standard actually neither prohibits nor
> discourages this.
I believe it does make it undefined behaviour.
> I don't have the latest version of the Standard or I might have
> interpreted it incorrectly, so it is fairly possible that I'm wrong. If
> that's the case, please prove me wrong. All quotations of the Standard
> are from "Committee Draft - August 3, 1998".
>
> The Standard clearly distinguishes between `identifier`s and `macro
> name`s. What you're reffering to is actually not an identifier. It's a
> macro name.
>
> [7.1.3 #1]
> -- All identifiers that begin with an underscore and either an
> uppercase letter or another underscore are always reserved for any use.
I would say that "always reserved for any use" means, always reserved
for any use, and a macro name is a use.
Also, in that section in n1124.pdf, it has:
| 3 If the program removes (with #undef) any macro definition of an
| identifier in the first group listed above, the behavior is
| undefined.
Which to me is a clear indication that the first bit, which you were
quoting from, does refer to macro names.
For something a little more specific, in n1124 we also have:
| 6.2 Concepts
| 6.2.1 Scopes of identifiers
| 1 An identifier can denote an object; a function; a tag or a member of
^^^^^^^^^^^^^^^^^^^^^^^^^^^
| a structure, union, or enumeration; a typedef name; a label name; a
| macro name; or a macro parameter. The same identifier can denote
^^^^^^^^^^
| different entities at different points in the program. A member of
| an enumeration is called an enumeration constant. Macro names and
| macro parameters are not considered further here, because prior to
| the semantic phase of program translation any occurrences of macro
| names in the source file are replaced by the preprocessing token
| sequences that constitute their macro definitions.
So that is clearly stating that a macro name is an identifier, so the
reserving of identifiers later in the standard clearly includes macro names.
6.4.2 Identifiers also refers back to 6.2.1 for what identifiers can
designate.
> -- All identifiers that begin with an underscore are always
> reserved for use as identifiers with file scope in both the ordinary and
> tag name spaces.
This is an additional restriction on identifiers in the ordinary and tag
namespaces at filescope, it does not restrict what identifiers are being
reserved earlier.
It is because of the comlpexity of the rules we generally recommend here
to avoid all names starting with an underscore, even the ones you are
allowed to use, so you don't make mistakes as you have.
> So yes, the Standard indeed marks these *identifiers* as reserved. There
> is no such clause for macro names except the following:
Wrong, because the earlier paragraph just says identifiers, it obviously
applies to all identifiers, and that includes macro names.
> [6.10.8]
> [#4] None of these macro names(1), nor the identifier defined, shall be
> the subject of a #define or a #undef preprocessing directive. Any other
> predefined macro names shall begin with a leading underscore
> followed by an uppercase letter or a second underscore.
>
> (1) Reffers to __LINE__, __FILE__, __DATE__, __TIME__, __STDC__,
> __STDC_VERSION__, __STDC_ISO_10646__, __STDC_IEC_559__,
> __STDC_IEC_559_COMPLEX__
>
> There is nothing said about reservation...
Not in there, but in the earlier part it does reserve them.
--
Flash Gordon
Living in interesting times.
Although my email address says spam, it is real and I read it.