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

Macros apparently have higher precedence than numbers #183

Open
Y-Less opened this issue Sep 6, 2017 · 8 comments
Open

Macros apparently have higher precedence than numbers #183

Y-Less opened this issue Sep 6, 2017 · 8 comments

Comments

@Y-Less
Copy link
Member

Y-Less commented Sep 6, 2017

#define xFF
new a = 0xFF;
printf("%d", a); // Prints 0

That probably shouldn't happen, but only if the symbol is a valid part of a number and used as such. I quite like this, that I saw in a recent include:

#define _Seconds * 1000
new a = 5_Seconds;
printf("%d", a); // Prints 5000

In that case, 5_ is not possibly a valid number so should be replaced; while things like 0x, 0b, or 5e could be so shouldn't be.

@Y-Less
Copy link
Member Author

Y-Less commented Sep 6, 2017

@VVWVV
Copy link
Contributor

VVWVV commented Sep 6, 2017

I guess this is not a bug. The preprocessor works first, and it does not analize the code. To fix the problem we need to rewrite the preprocessor.

@Y-Less
Copy link
Member Author

Y-Less commented Sep 6, 2017

I guess this is not a bug.

To fix the problem

Which is it? If I write:

#define xFF
new AxFF = 255;
new a = AxFF;
printf("%d", a); // Prints 255

That is fine, because macros don't match in the middle of symbols, so they probably shouldn't match in the middle of valid numbers either.

@VVWVV
Copy link
Contributor

VVWVV commented Sep 6, 2017

Sorry) Yeah, the preprocessor skips all non-alphabetic characters here: https://github.com/Zeex/pawn/blob/master/source/compiler/sc2.c#L1772-L1780

@Dayvison
Copy link

Don't skip if have a-z @ _ before the number

#define test -

0test
10test
_0test

Output:

0-
10-
_0test

@Y-Less
Copy link
Member Author

Y-Less commented Oct 24, 2017

_ and @ should be counted - they can start legitimate tokens. I literally have a macros called ___1 and @1.

@Dayvison
Copy link

Yeah is just a example, what i want to say is if as any character before number, don't match.

@Dayvison
Copy link

Dayvison commented Oct 24, 2017

What i tried

#define hook%1(%2) forward UNIQUE_FUNCTION<@yH0%1@...>(%2);UNIQUE_FUNCTION<@yH0%1@...>(%2)
// Strip out extra spaces (nicely recursive)
#define @yH0%0\32;%1(%2) @yH0%1(%2)

#define tag:: tag_
hook tag::function()

Changed @yH_ to @yH0

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

No branches or pull requests

5 participants