Topic: Long identifiers, part 2
Author: David R Tribble <david.tribble@noSPAM.central.beasys.com>
Date: 1998/11/12 Raw View
David R Tribble <david.tribble@noSPAM.central.beasys.com> writes:
>>//====================================================================
>>// bigid2.cpp
>>// Test program to demonstrate ISO standard recommendations for
>>// minimum identifier lengths.
Steve Clamage wrote:
> There's a bug in the code. Clearly there needs to be a "::" between
> NREF256 and s_mem, but not between NREF256 and big_named_objectB.
> With the macros defined the way they are you get :: in both places.
Thanks. The complete corrected source follows (and hopefully I won't
have to post any other corrections). The source is also available at
<http://www.flash.net/~dtribble/src/bigid2.cpp>.
-- David R. Tribble, dtribble@technologist.com --
//======================================================================
// bigid2.cpp
// Test program to demonstrate ISO standard recommendations for
// minimum identifier lengths.
//
// References
// ISO/IEC 14882:1998(E), Annex B.
//
// 1.00, 1998-10-15, David R Tribble.
// First cut.
// 1.01, 1998-10-27, David R Tribble.
// Made generated names all unique.
// 1.02, 1998-11-12, David R Tribble.
// Fixed syntax error in NREF (as suggested by Steve Clamage).
//
// Written by David R. Tribble, 1998.
// This source code is in the public domain.
//----------------------------------------------------------------------
// Preprocessor macro magic
#define K(a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p,q) \
a##b##c##d##e##f##g##h##i##j##k##l##m##n##o##p##q
// A 1021+N-character name
#define B1024(c) \
K(B234567890123456789012345678901234567890123456789012345678901234,\
B234567890123456789012345678901234567890123456789012345678901234,\
B234567890123456789012345678901234567890123456789012345678901234,\
B234567890123456789012345678901234567890123456789012345678901234,\
B234567890123456789012345678901234567890123456789012345678901234,\
B234567890123456789012345678901234567890123456789012345678901234,\
B234567890123456789012345678901234567890123456789012345678901234,\
B234567890123456789012345678901234567890123456789012345678901234,\
B234567890123456789012345678901234567890123456789012345678901234,\
B234567890123456789012345678901234567890123456789012345678901234,\
B234567890123456789012345678901234567890123456789012345678901234,\
B234567890123456789012345678901234567890123456789012345678901234,\
B234567890123456789012345678901234567890123456789012345678901234,\
B234567890123456789012345678901234567890123456789012345678901234,\
B234567890123456789012345678901234567890123456789012345678901234,\
B23456789012345678901234567890123456789012345678901234567890_,c)
// 256-level class decl head
#define CLASS_HEAD(c) class B1024(c) { public:
#define CLASS_HEAD4(c) \
CLASS_HEAD(c##1)\
CLASS_HEAD(c##2)\
CLASS_HEAD(c##3)\
CLASS_HEAD(c##4)
#define CLASS_HEAD16(c) \
CLASS_HEAD4(c##A)\
CLASS_HEAD4(c##B)\
CLASS_HEAD4(c##C)\
CLASS_HEAD4(c##D)
#define CLASS_HEAD256 \
CLASS_HEAD16(W)\
CLASS_HEAD16(X)\
CLASS_HEAD16(Y)\
CLASS_HEAD16(Z)
// 256-level class decl tail
#define CLASS_TAIL };
#define CLASS_TAIL4 \
CLASS_TAIL\
CLASS_TAIL\
CLASS_TAIL\
CLASS_TAIL
#define CLASS_TAIL16 \
CLASS_TAIL4\
CLASS_TAIL4\
CLASS_TAIL4\
CLASS_TAIL4
#define CLASS_TAIL256 \
CLASS_TAIL16\
CLASS_TAIL16\
CLASS_TAIL16\
CLASS_TAIL16
// A 256-level qualified name
#define NREF(c) B1024(c)
#define NREF4(c) \
NREF(c##1)::\
NREF(c##2)::\
NREF(c##3)::\
NREF(c##4)
#define NREF16(c) \
NREF4(c##A)::\
NREF4(c##B)::\
NREF4(c##C)::\
NREF4(c##D)
#define NREF256 \
NREF16(W)::\
NREF16(X)::\
NREF16(Y)::\
NREF16(Z)
//----------------------------------------------------------------------
// Class B2345678901234567890123456789012...
// This class has a name that is 1024 characters long, and has 256
// nested classes, each of which has a different 1024-character
// name.
//----------------------------------------------------------------------
CLASS_HEAD256
static int s_mem;
int m_mem;
CLASS_TAIL256
//----------------------------------------------------------------------
// big_named_objectB
// This is an instance of the class declared above.
//
// If this object (which has external linkage) is successfully
// instantiated, then the compiler appears to properly support very
// long identifiers.
//----------------------------------------------------------------------
/*static*/ int NREF256::s_mem = 234;
static class NREF256 big_named_objectB;
//----------------------------------------------------------------------
// ::main()
// Dummy entry function.
//----------------------------------------------------------------------
int main()
{
return (0);
}
// End bigid2.cpp
[ comp.std.c++ is moderated. To submit articles, try just posting with ]
[ your news-reader. If that fails, use mailto:std-c++@ncar.ucar.edu ]
[ --- Please see the FAQ before posting. --- ]
[ FAQ: http://reality.sgi.com/austern_mti/std-c++/faq.html ]
Author: David R Tribble <david.tribble@noSPAM.central.beasys.com>
Date: 1998/11/11 Raw View
Annex B of the ISO C++ standard (ISO/IEC 14882:1998(E)), entitled
"Implementation quantities", describes some guidelines for minimum
sizes for several implementations limits. In particular, it
recommends these minimum limits:
- 1024 initial characters in an internal identifier or macro
name.
- 256 levels of nested class, structure, or union definitions in
a single struct-declaration-list.
Given these two limitations, I've devised a simple test program with
which to judge compiler conformance. I'm curious as to how many
compilers can compile the program (I haven't found any yet; some
preprocessors core dump). Source code follows (and can also be
found at http://www.flash.net/~dtribble/src/bigid2.cpp).
-- David R. Tribble, dtribble@technologist.com --
//======================================================================
// bigid2.cpp
// Test program to demonstrate ISO standard recommendations for
// minimum identifier lengths.
//
// References
// ISO/IEC 14882:1998(E), Annex B.
//
// 1.00, 1998-10-15, David R Tribble.
// First cut.
// 1.01, 1998-10-27, David R Tribble.
// Made generated names all unique.
//
// Written by David R. Tribble, 1998.
// This source code is in the public domain.
//----------------------------------------------------------------------
// Preprocessor macro magic
#define K(a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p,q) \
a##b##c##d##e##f##g##h##i##j##k##l##m##n##o##p##q
// A 1021+N-character name
#define B1024(c) \
K(B234567890123456789012345678901234567890123456789012345678901234,\
B234567890123456789012345678901234567890123456789012345678901234,\
B234567890123456789012345678901234567890123456789012345678901234,\
B234567890123456789012345678901234567890123456789012345678901234,\
B234567890123456789012345678901234567890123456789012345678901234,\
B234567890123456789012345678901234567890123456789012345678901234,\
B234567890123456789012345678901234567890123456789012345678901234,\
B234567890123456789012345678901234567890123456789012345678901234,\
B234567890123456789012345678901234567890123456789012345678901234,\
B234567890123456789012345678901234567890123456789012345678901234,\
B234567890123456789012345678901234567890123456789012345678901234,\
B234567890123456789012345678901234567890123456789012345678901234,\
B234567890123456789012345678901234567890123456789012345678901234,\
B234567890123456789012345678901234567890123456789012345678901234,\
B234567890123456789012345678901234567890123456789012345678901234,\
B23456789012345678901234567890123456789012345678901234567890_,c)
// 256-level class decl head
#define CLASS_HEAD(c) class B1024(c) { public:
#define CLASS_HEAD4(c) \
CLASS_HEAD(c##1)\
CLASS_HEAD(c##2)\
CLASS_HEAD(c##3)\
CLASS_HEAD(c##4)
#define CLASS_HEAD16(c) \
CLASS_HEAD4(c##A)\
CLASS_HEAD4(c##B)\
CLASS_HEAD4(c##C)\
CLASS_HEAD4(c##D)
#define CLASS_HEAD256 \
CLASS_HEAD16(W)\
CLASS_HEAD16(X)\
CLASS_HEAD16(Y)\
CLASS_HEAD16(Z)
// 256-level class decl tail
#define CLASS_TAIL };
#define CLASS_TAIL4 \
CLASS_TAIL\
CLASS_TAIL\
CLASS_TAIL\
CLASS_TAIL
#define CLASS_TAIL16 \
CLASS_TAIL4\
CLASS_TAIL4\
CLASS_TAIL4\
CLASS_TAIL4
#define CLASS_TAIL256 \
CLASS_TAIL16\
CLASS_TAIL16\
CLASS_TAIL16\
CLASS_TAIL16
// A 256-level qualified name
#define NREF(c) B1024(c)::
#define NREF4(c) \
NREF(c##1)\
NREF(c##2)\
NREF(c##3)\
NREF(c##4)
#define NREF16(c) \
NREF4(c##A)\
NREF4(c##B)\
NREF4(c##C)\
NREF4(c##D)
#define NREF256 \
NREF16(W)\
NREF16(X)\
NREF16(Y)\
NREF16(Z)
//----------------------------------------------------------------------
// Class B2345678901234567890123456789012...
// This class has a name that is 1024 characters long, and has 256
// nested classes, each of which has the same 1024-character name.
//----------------------------------------------------------------------
CLASS_HEAD256
static int s_mem;
int m_mem;
CLASS_TAIL256
//----------------------------------------------------------------------
// big_named_objectB
// This is an instance of the class declared above.
//
// If this object (which has external linkage) is successfully
// instantiated, then the compiler appears to properly support very
// long identifiers.
//----------------------------------------------------------------------
/*static*/ int NREF256 s_mem = 234;
static class NREF256 big_named_objectB;
//----------------------------------------------------------------------
// ::main()
// Dummy entry function.
//----------------------------------------------------------------------
int main()
{
return (0);
}
// End bigid2.cpp
[ comp.std.c++ is moderated. To submit articles, try just posting with ]
[ your news-reader. If that fails, use mailto:std-c++@ncar.ucar.edu ]
[ --- Please see the FAQ before posting. --- ]
[ FAQ: http://reality.sgi.com/austern_mti/std-c++/faq.html ]
Author: clamage@Eng.Sun.COM (Steve Clamage)
Date: 1998/11/12 Raw View
David R Tribble <david.tribble@noSPAM.central.beasys.com> writes:
>//======================================================================
>// bigid2.cpp
>// Test program to demonstrate ISO standard recommendations for
>// minimum identifier lengths.
>//
> ...
>CLASS_HEAD256
> static int s_mem;
> int m_mem;
>CLASS_TAIL256
>/*static*/ int NREF256 s_mem = 234;
>static class NREF256 big_named_objectB;
There's a bug in the code. Clearly there needs to be a "::" between
NREF256 and s_mem, but not between NREF256 and big_named_objectB.
With the macros defined the way they are you get :: in both places.
I generated preprocessor output, then removed the extraneous "::",
and the Sun C++ compiler handled the code with no problem.
The compilers, linkers, and Solaris object format have no practical
limits on name length, which is not to say you can't concoct an
example that runs into a limit. We test with names in excess of 100K
characters with no problems.
--
Steve Clamage, stephen.clamage@sun.com
---
[ comp.std.c++ is moderated. To submit articles, try just posting with ]
[ your news-reader. If that fails, use mailto:std-c++@ncar.ucar.edu ]
[ --- Please see the FAQ before posting. --- ]
[ FAQ: http://reality.sgi.com/austern_mti/std-c++/faq.html ]