Address unintuitive macro expansion #637
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This will eventually be necessary because of the version of ColorzCore I am working on (see FireEmblemUniverse/ColorzCore#63), which hopefully will make it as an "official" release, will break this.
Explanation
Because of a quirk in the current version of ColorzCore, the body of the object-like macro "MaxPlayerUnits" is evaluated early as a number, and results in the single token "0x3F" (63) at definition time.
This results eventually in the following statement when expanded:
(keeping macro names for the parts that aren't relevant for clarity)
Now, I made a change to the way '#define' works that allows it to take any sequence of tokens as macro body, not just an expression or a string. I believe it's an improvement but is means that the body of "MaxPlayerUnits" is cannot be evaluated early anymore, and keeps being the sequence ["62", "+", "1"].
Eventually, when expanded:
This is not the same as above because of operator precedence.
Notes:
#define MaxPlayerUnits "62+1"
breaks)(I might have to add some hacks in ColorzCore to at least warn users of such cases when they upgrade).
The fix
Put parenthesizes around the expression in the definition. I also added quotes for good measure.