Skip to content

Can't take the address of an extern variable as a constant value #5344

@yvt

Description

@yvt
extern var external_variable: u32;
export const p_external_variable = &external_variable; // Error

var internal_variable: u32 = 42;
export const p_internal_variable = &internal_variable; // OK

Expected: Successful compilation

Actual:

<source>:2:36: error: cannot store runtime value in compile time variable
export const p_external_variable = &external_variable;
                                   ^

Compiler Explorer Link

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugObserved behavior contradicts documented or intended behaviorcontributor friendlyThis issue is limited in scope and/or knowledge of Zig internals.

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions