Edit: I have readed What are the rules about using an underscore in a C++ identifier?
that post does not answer what is explicitly allowed in [reserved.names](17.6.4.3)/2 and why a name that begins with an underscore followed by an lowercase letter in local namespace is explicitly allowed. In fact, I don't really think that is explicitly allowed and might be UB if we do that.
the following is the original question:
first at all, let's see the standard(ISO/IEC 14882:2011(E))
[reserved.names](17.6.4.3) said:
1 The C++ standard library reserves the following kinds of names:
— macros
— global names
— names with external linkage2 If a program declares or defines a name in a context where it is reserved, other than as explicitly allowed by this Clause, its behavior is undefined.
[global.names](17.6.4.3.2) said:
1 Certain sets of names and function signatures are always reserved to the implementation:
— Each name that contains a double underscore __ or begins with an underscore followed by an uppercase letter (2.12) is reserved to the implementation for any use.
— Each name that begins with an underscore is reserved to the implementation for use as a name in the global namespace.
for now, if we have the following code:
int _a1;
int _A1;
void f()
{
int _a2 = 0;
int _A2 = 0;
}
Q1: Is the behavor is undefined if we defines _a1?
Q2: Is the behavor is undefined if we defines _A1?
Q3: Is the behavor is undefined if we defines _a2?
Q4: Is the behavor is undefined if we defines _A2?
In the standard [global.names](17.6.4.3.2) tells us Each name that begins with an underscore is reserved to the implementation for use as a name in the global namespace.
Q5: Does that means we can use a name that begins with an underscore followed by an lowercase letter in local namespace? If so is that so-called explicitly allowed?
In fact I have read a answer that tells me that I can use a name that begins with an underscore followed by an lowercase letter, but I'm not sure if that is explicitly allowed so I have no idea about whether that answer is correct.
Aucun commentaire:
Enregistrer un commentaire