#ArrayList segfaults on struct type

1 messages · Page 1 of 1 (latest)

tawdry grotto
#

My program just segfaults when I try to append a struct type to my array list

const std = @import("std");

const Foo = struct {
  name: [*:0]const u8,
  id:   u32,
};

pub fn main() void {

  var gpa = std.heap.GeneralPurposeAllocator(.{}).init;

  defer {
    if (gpa.deinit() == .leak) {
      std.debug.panic("Leaked memory.", .{});
    }
  }

  const foo = Foo {.id = 0, .name = "hello"};
  
  var arr = std.ArrayList(Foo).init(gpa.allocator());
  defer arr.deinit();

  arr.append(foo) catch unreachable;
}
umbral sail
#

I don't think your program compiles.

tawdry grotto
#

i've just simplified it to this but haven't tested on this

#

yes it compiles now, i've found the problem and it was something completely unrelated to this, thanks anyway