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

Postfix increment and decrement operator not working #10

Open
hd-COO7 opened this issue Mar 1, 2023 · 4 comments
Open

Postfix increment and decrement operator not working #10

hd-COO7 opened this issue Mar 1, 2023 · 4 comments

Comments

@hd-COO7
Copy link

hd-COO7 commented Mar 1, 2023

Prefix increment/decrement operator seems to be working fine but postfix increment/decrement operator throws error.
Code to reproduce

int i =0;
while(i < 5) {
    i++;
}

This behaviour is not limited to any type. Was able to reproduce this for pointers was well in similar fashion

@calroc
Copy link
Contributor

calroc commented Mar 1, 2023

Also --var; as a statement by itself compiles but doesn't seem to actually decrement the variable.

@maximecb
Copy link
Owner

maximecb commented Mar 1, 2023

Also --var; as a statement by itself compiles but doesn't seem to actually decrement the variable.

Oh that must be because it evaluates to the negation of the negation of. Should be super easy to implement prefix decrement since there's already an implementation of ++var. PR welcome.

If you do add a PR, make sure to add one or more tests as well. There are tests in codegen.rs and under ncc/tests/expressions.c.

@maximecb
Copy link
Owner

maximecb commented Mar 1, 2023

Prefix increment/decrement operator seems to be working fine but postfix increment/decrement operator throws error. Code to reproduce

int i =0;
while(i < 5) {
    i++;
}

This behaviour is not limited to any type. Was able to reproduce this for pointers was well in similar fashion

At the moment we have pre-increment but not post-increment because it's slightly trickier to implement. PR welcome.

@maximecb
Copy link
Owner

maximecb commented Mar 2, 2023

Also --var; as a statement by itself compiles but doesn't seem to actually decrement the variable.

Just added prefix decrement, --var works now.

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

No branches or pull requests

3 participants