Skip to content

@ptrToInt error: unable to evaluate constant expression #5295

@artob

Description

@artob

With 0.6.0, @ptrToInt() surprisingly cannot be used as a constant expression:

Screen Shot 2020-05-08 at 06 56 12

The contents of the aforementioned function_table.zig minimal reproduction case:

const std = @import("std");
const testing = std.testing;

export fn my_func() void {}

const ExportedFunction = struct {
  name: []const u8,
  ptr: usize, // function types vary
};

const functions = [_]ExportedFunction {
  .{.name = "my_func", .ptr = @ptrToInt(&my_func)},
};

test "reproduce error: unable to evaluate constant expression" {
  testing.expect(functions[0].ptr != 0);
}

By the way, in case there's any better way to create a function lookup table storing function pointers (with varying function type signatures) to exported functions, I'm all ears...

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions