Skip to content

Using constants at compile time to define vector lengths #3469

Closed
@brendanzab

Description

@brendanzab

I'm trying to use a constant at compile time to define the length of some vectors:

/* Gamma ramps */
const GLFW_GAMMA_RAMP_SIZE              : int = 256;

/* Gamma ramp */
struct GLFWgammaramp {
    red     : [c_ushort * GLFW_GAMMA_RAMP_SIZE],      // unsigned short red[GLFW_GAMMA_RAMP_SIZE];
    green   : [c_ushort * GLFW_GAMMA_RAMP_SIZE],      // unsigned short green[GLFW_GAMMA_RAMP_SIZE];
    blue    : [c_ushort * GLFW_GAMMA_RAMP_SIZE]       // unsigned short blue[GLFW_GAMMA_RAMP_SIZE];
}

(code from glfw3-rs)

I get this error:

 % rustc test.rs 
test.rs:6:26: 6:46 error: expected `]` but found `GLFW_GAMMA_RAMP_SIZE`
test.rs:6     red     : [c_ushort * GLFW_GAMMA_RAMP_SIZE],      // unsigned short red[GLFW_GAMMA_RAMP_SIZE];

Is this a bug or by design?

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-frontendArea: Compiler frontend (errors, parsing and HIR)E-hardCall for participation: Hard difficulty. Experience needed to fix: A lot.

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions