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 with side effects (bug) #385

Closed
therontarigo opened this issue May 10, 2024 · 0 comments
Closed

Ternary operator with side effects (bug) #385

therontarigo opened this issue May 10, 2024 · 0 comments

Comments

@therontarigo
Copy link
Contributor

Encountered when trying to minify a shader that already used some codegolf tricks.
This legal GLSL:

out vec4 O;
uniform int k;
void main() {
  int d=0,e=0;
  k==0 ? d=1 : e=2 ;
  // if(k==0) d=1 ; else e=2 ;  // semantically equivalent
  O.x=d;
  O.y=e;
}

results in both assignments being evaluated:

out vec4 O;
uniform int k;
void main()
{
  int d=0,e=0;
  d=1,e=2;
  O.x=d;
  O.y=e;
}

using the commented line instead, result is correct, but misses the opportunity to use ternary operator trick.

eldritchconundrum added a commit that referenced this issue May 10, 2024
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

1 participant