Coder Social home page Coder Social logo

Comments (2)

johnstiles-google avatar johnstiles-google commented on August 22, 2024

The docs do say "Variables declared in init-expression or condition-expression are only in scope until the end of the sub-statement of the for loop." but don't indicate that the for-statement itself actually introduces a new scope, only that the sub-statement does not introduce one.

Interestingly, the grammar includes statement_no_new_scope to cover this case, but doesn't clearly indicate where scopes are introduced.

from glsl.

johnstiles-google avatar johnstiles-google commented on August 22, 2024

I also discovered Section 4.2 states: "If (a variable) is declared in a while test or a for statement, then it is scoped to the end of the following sub-statement." This is a great clue but it doesn't actually clarify that for-statements are scopes.

In particular, we can demonstrate that in glslang, for-statements are scopes even when they do not declare any variables at all:

void main() {
    int x=1; for (;;) int x=2;
}

This compiles in glslang.

from glsl.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.