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

## with empty macro argument is wrong. #91

Open
mrolle45 opened this issue Jan 17, 2024 · 1 comment
Open

## with empty macro argument is wrong. #91

mrolle45 opened this issue Jan 17, 2024 · 1 comment
Labels

Comments

@mrolle45
Copy link

C99 Standard 6.10.3.3 (the ## operator) says that the name of an empty argument should be replaced with a placeholder, before performing the operator. Concatenating a placeholder with another token (possibly another placeholder) results in the other token. Placeholders are discarded after all ## operators have been performed.

The code in preprocessor.py simply removes the empty argument's name from the replacement text, causing the next or previous token to be used instead of a placeholder.

Examples:

#define greet(x, y) Hello x ## y
greet(Abe, Lincoln)            -> Hello, AbeLincoln
greet(Abe, )                   -> Error: ## at the end of the replacement text, not Hello Abe
greet(, Lincoln)               -> HelloLincoln, not Hello Lincoln

The fix is to simply follow the Standard strictly, and make a temporary token whose value is an empty string and which has a different type which would allow it to be later removed from the results.

@ned14 ned14 added the bug label Jan 17, 2024
@ned14
Copy link
Owner

ned14 commented Jan 17, 2024

Thanks for the BR

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants