The documentation is now generated from markdown. Samples are generated from the tutorial pages. Testing is done by a Python script which runs the tests for a large number of compilers. This version is not very developer-friendly - the Python scripts need ways of limiting what compilers they try to run. If you don't have 15 compilers installed, you won't be able to run the tests in this commit. Fix coming soon.
2.1 KiB
Extending macro limits
The ENUM macro makes heavy use of the preprocessor. The preprocessor can't
perform intelligent operations on sequences of tokens with arbitrary lengths
— the operations must be bounded. The result is that there are two size
limits: on the number of constants that a Better Enum can have, and on the
maximum length of a constant name under certain conditions. If you run into
either of these limits, follow the steps on this page to increase them.
The conditions for the constant name length limit rarely apply. They are:
- you are compiling an enum with compile-time string trimming, a.k.a. a "slow enum", which is only enabled when you do this, and
- you have a constant with an initializer.
Constants without initializers can always have arbitrarily-long names.
The default limits are 64 constants and 23 characters for names of slow enum constants that have initializers. To extend these limits:
-
Pick your desired limits. I will use 512 constants and 63 characters as an example. Add 1 to the number of characters to account for the null terminator — our numbers are now 512 and 64.
-
Get
make_macros.pyfrom your copy of the Better Enums distribution or from GitHub. -
You will run this script to generate a header file containing some replacement macros for
enum.hto use. Pick a name for this file and a location somewhere in your include path. I will assume that this file iscommon/enum_macros.h. -
Run
python make_macros.py 512 64 > common/enum_macros.h. -
Define
BETTER_ENUMS_MACRO_FILE <common/enum_macros.h>before includingenum.h. This is typically done by supplying extra flags to the compiler on the command line:- For g++ and clang++,
-DBETTER_ENUMS_MACRO_FILE='<common/enum_macros.h>' - For VC++,
\DBETTER_ENUMS_MACRO_FILE='<common/enum_macros.h>'
- For g++ and clang++,
-
Enjoy the looser limits. Just watch out — increasing the second number can really slow down compilation of compile-time trimming enums.
-
You don't need
make_macros.pyanymore. It's not part of your build process and you can delete it.