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

Ternary operator executes both sides #3

Open
jpoirier opened this issue Jun 13, 2015 · 1 comment
Open

Ternary operator executes both sides #3

jpoirier opened this issue Jun 13, 2015 · 1 comment
Labels

Comments

@jpoirier
Copy link
Owner

Consider:
int a = 1;
a?printf("a!=0\n"):printf("a==0\n");

Based on this, since a == 1 (rather, since a != 0), only "a!=0" should be printed. If instead is set to 0, only "a == 0" should be printed.

Regardless of the value of a, both printf()s are performed.

This is using picoc 2.1 on OS X.

Issue copied from: https://code.google.com/p/picoc/issues/detail?id=184

@jpoirier jpoirier added the bug label Jun 13, 2015
@jpoirier
Copy link
Owner Author

it seems that a semicolon is required at the end of the first printf for it to work properly, e.g.

a ? printf("a!=0\n"); : printf("a==0\n");

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

1 participant