Skip to content

Cannot evaluate @ptrToInt at comptime #15080

@lovely-error

Description

@lovely-error

Zig Version

0.11.0-dev.2194+626a75bbc

Steps to Reproduce and Observed Behavior

When building a file containing this code...

const std = @import("std");

fn c () void {}

const b = @ptrToInt(&c);

pub fn main () void {
    std.debug.print("{}", .{b});
}

... with this parameters...

zig build-exe f.zig

... I get the following error...

f.zig:40:11: error: unable to evaluate comptime expression
const b = @ptrToInt(&c);
          ^~~~~~~~~~~~~
f.zig:40:21: note: operation is runtime due to this operand
const b = @ptrToInt(&c);

This does not seem right to me, since it is okay to take a function address and print in main. For some reason the compiler is unable to understand a slightly more compilcated arrangement of things. Why is that, I wonder?

Expected Behavior

Should work just fine.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugObserved behavior contradicts documented or intended behaviorenhancementSolving this issue will likely involve adding new logic or components to the codebase.

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions