In discussing design possibilities for a project that has a very large number of constants and bit patterns to be defined, the question came up about how many #defines can a standard compiler handle? I assume it is a very large number, but we were curious to know if there is an actual upper bound.
In mathematics, a limit is the value that a function (or sequence) approaches as the input (or index) approaches some value.
limit, restrict, circumscribe, confine mean to set bounds for. limit implies setting a point or line (as in time, space, speed, or degree) beyond which something cannot or is not permitted to go.
“He has no limits.” or “They have no limits.” You use “have” when the subject of the verb (either “he” or “they” in the examples above) is plural, and also when the subject is “I” or “you” (“I have no limits.”, “You have no limits.”) You have “has” when the subject is singular, unless the subject is “I” or “you”.
For a "standard compiler":
5.2.4.1: "Translation limits"
The implementation shall be able to translate and execute at least one program that contains at least one instance of every one of the following limits
...
4095 macro identifiers simultaneously defined in one preprocessing translation unit
Note the slightly odd way of phrasing the requirement. Implementations could satisfy it by having a single "golden program" which they recognise and compile as a special case, although that would be akin to rigging benchmarks. In practice you can read the standard as saying that if your implementation imposes a limit other than available memory, then that limit should be at least 4095. Beyond 4095 you are relying on implementation-specific behavior to an extent.
Some compilers (Microsoft) impose some implementation limits which are less than the standard says. These are listed somewhere on MSDN I think, but possibly only for C++. As far as C goes, since I'm quoting C99 it might not be relevant to MSVC anyway.
For GCC and MSVC in particular, it shouldn't be too hard to test whether a given implementation imposes an arbitrary limit, perhaps easier than finding it documented :-) Auto-generate files containing nothing but great long lists of #define
, see what the preprocessor makes of them.
I have never heard of anyone running out. Ever.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With