Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Function macro expansion bug when multi argument macro arg has same name as user input #32

Merged
merged 3 commits into from
Jul 29, 2024

Conversation

AndrewRayCode
Copy link
Collaborator

@AndrewRayCode AndrewRayCode commented Jul 28, 2024

Reproduce

#define F(x, y) x + y
F(y, x)

gets expanded to

x + x

because the replacement of each argument is a separate string replacement pass. So first it replaces the first argument, x, with what the user supplied, y, making the string y + y. Then it goes on to replace the second argument, y, with the user supplied x, making the string x + x.

This bug is triggered when a function macro has more than one argument, and the second argument (in this case y also matches what the user replace the first argument with.

Fix

I switched the replacement to be a single pass replace, so there is no second pass to clobber the first replacement.

Addresses #31

@AndrewRayCode AndrewRayCode changed the title Function macro expansion bug Function macro expansion bug when multi argument macro arg has same name as user input Jul 29, 2024
@AndrewRayCode AndrewRayCode merged commit dccca4e into main Jul 29, 2024
1 check passed
@AndrewRayCode AndrewRayCode deleted the macro-function-bug branch July 29, 2024 01:44
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant