I want to replace directive
#define MAX_LINE 15
with variable value.
For example of behavior, if something ( text ) contains 15 or more lines #define MAX_LINE to return 15
else if the text contains less than 15 lines #define MAX_LINE to return numbers of lines.
for( i = 0; i < MAX_LINE; i++ ) {
/* print lines in expandable menu window */
}
is this possible?
#defines simply replace some text with some other text. You could, for example, use this:Then you can use
MAX_LINESas before in some statements. However, it won’t work in all situations. You may have had code that looked like this:With the old
#define,MAX_LINESwas 15, so it expanded to this:That should be valid in any standards-compliant compiler. However, say you used our new
#define. Expanded, it would look like this:Supposing that was a global declaration, that would be invalid. Even if it was just a local declaration, it would only be valid if the compiler supports variable-length arrays.
If I were you, I’d simply try to get whatever you’re trying to do to work without
#defineingMAX_LINESto a non-constant expression; it’s clearer that way and it will be more obvious where it would be invalid to useMAX_LINES.