lua-users home
lua-l archive

[Date Prev][Date Next][Thread Prev][Thread Next] [Date Index] [Thread Index]


On Sat, 10 May 2008, Alexander Gladysh wrote:
>
> Actually, there is a subtle difference. As I understand, plain C
> reserves all names at any scope, which begin with undersore or
> uppercase letter.

No, underscore _followed_by_ an uppercase letter. there are other
restrictions too. See section 7.1.3 of the standard - C99 with technical
corrigenda 1 and 2 can be read at
http://www.open-std.org/jtc1/sc22/wg14/www/docs/n1124.pdf
It says:

Each header declares or defines all identifiers listed in its associated
subclause [i.e. the header's part of section 7], and optionally declares
or defines identifiers listed in its associated future library directions
subclause [i.e. section 7.26] and identifiers which are always reserved
either for any use or for use as file scope identifiers.

—All identifiers that begin with an underscore and either an uppercase
letter or another underscore are always reserved for any use.

—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.
[i.e. static or global variables and functions, and structure and union tags]

—Each macro name in anyo f the following subclauses (including the future
library directions) is reserved for use as specified if any of its
associated headers is included; unless explicitly stated otherwise (see
7.1.4).

—All identifiers with external linkage in anyo ft he following subclauses
(including the future library directions) are always reserved for use as
identifiers with external linkage. (The list of reserved identifiers with
external linkage includes errno, math_errhandling, setjmp, and va_end.)

—Each identifier with file scope listed in anyo ft he following subclauses
(including the future library directions) is reserved for use as a macro
name and as an identifier with file scope in the same name space if
any of its associated headers is included.

Section 7.26 reserves all external functions that start with is or to or
str or mem or wcs, some of which you might reasonably want to use!

> C++ reserves global-scope names with leading underscore, and names in
> any scope, if such name contain double underscore at any position.

The C++ double underscore restriction is the most obvious extra
restriction compared to C. See section 17.4.3.1 of
http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2007/n2461.pdf

> That is, to write code to be compiled portably both as C and as C++,
> one should not use names with leading underscore and should not use
> double underscore at all.

Yup.

There's a useful summary of which identifiers to avoid at:
http://web.archive.org/web/20040209031039/http://oakroadsystems.com/tech/c-predef.htm

Tony.
-- 
f.anthony.n.finch  <dot@dotat.at>  http://dotat.at/
LUNDY FASTNET IRISH SEA SHANNON: VARIABLE MAINLY EAST OR NORTHEAST 3 OR 4.
SLIGHT OR MODERATE. FOG PATCHES. MODERATE OR GOOD, OCCASIONALLY VERY POOR.