# What does "error: expected type '\*T', found '\*const T" mean? (Where T is some type)

**URL:** <https://ziggit.dev/t/what-does-error-expected-type-t-found-const-t-mean-where-t-is-some-type/1320>\
**Category:** Help\
**Tags:** language, memory-management\
**Created:** [July 31, 2023, 4:25am UTC](https://ziggit.dev/t/what-does-error-expected-type-t-found-const-t-mean-where-t-is-some-type/1320 "2023-07-31T04:25:34Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![nitinprakash96](https://ziggit.dev/letter_avatar_proxy/v4/letter/n/f05b48/32.png) [@nitinprakash96](https://ziggit.dev/u/nitinprakash96)\
**Post date:** [July 31, 2023, 4:25am UTC](https://ziggit.dev/t/what-does-error-expected-type-t-found-const-t-mean-where-t-is-some-type/1320/1 "2023-07-31T04:25:34Z")

</div>

I’m fairly new to Zig so I might be missing something obvious.  
But in any case, I have the following error but I’m not sure what to make of it:

```zig
~/src/main.zig:82:39: error: expected type '*mem.Allocator', found '*const mem.Allocator'
        var conv = try Converter.init(&arena.allocator(), std.io.getStdOut().writer(), bufSize);
                                      ^ ~~~~~~~~~~~~~~~~~
~/src/main.zig:82:39: note: cast discards const qualifier
referenced by:
    comptime_0: /usr/local/Cellar/zig/0.10.1/lib/zig/std/start.zig:59:50
    remaining reference traces hidden; use '-freference-trace' to see all reference traces

```

And the code that generates it:

```zig
// in main.zig
const std = @import("std");
const Converter = @import("./converter.zig").Converter;

pub fn main() !void {
  var arena = std.heap.ArenaAllocator.init(std.heap.page_allocator);
  defer arena.deinit();

  var conv = try Converter.init(&arena.allocator(), std.io.getStdOut().writer(), bufSize);
  // other operations
}

```

And in `converter.zig`:

```zig
const std = @import("std");

pub const Converter = struct {
    const BufferedWriter = std.io.BufferedWriter(4096, std.fs.File.Writer);

    allocator: *std.mem.Allocator,
    csvBuf: []u8,
    hdrBuf: []u8,
    rowBuf: []u8,
    keys: [][]const u8,
    out: BufferedWriter,

    const Self = @This();

    // Initialize the converter.
    pub fn init(allocator: *std.mem.Allocator, writer: anytype, rowBufSize: u32) !Self {
        var s = Converter{
            .allocator = allocator,
            .out = std.io.bufferedWriter(writer),
            .csvBuf = try allocator.alloc(u8, rowBufSize),
            .hdrBuf = try allocator.alloc(u8, rowBufSize),
            .rowBuf = try allocator.alloc(u8, rowBufSize),
            .keys = undefined,
        };

        return s;
    }

// other methods like `deinit()` etc

```

What I’d like to understand the point where this `const` comes into play.

---

<div class="post-metadata">

**Author:** ![zraineri](https://ziggit.dev/user_avatar/ziggit.dev/zraineri/32/755_2.png) [@zraineri](https://ziggit.dev/u/zraineri)\
**Post date:** [July 31, 2023, 4:37am UTC](https://ziggit.dev/t/what-does-error-expected-type-t-found-const-t-mean-where-t-is-some-type/1320/2 "2023-07-31T04:37:48Z")

</div>

Welcome to the forum!

You’re returning the allocator directly from its construction with `&arena.allocator()` here:

```zig
var conv = try Converter.init(&arena.allocator(), std.io.getStdOut().writer(), bufSize);

```

Variables are immutable unless defined otherwise.

It will work if you instead do this:

```zig
var allocator = arena.allocator();
var conv = try Converter.init(&allocator, std.io.getStdOut().writer(), bufSize);

```

Which first defines it as a mutable variable and then passes a reference to that mutable variable into `Converter.init`

This error just means it expected a mutable reference but received an immutable one

---

<div class="post-metadata">

**Author:** ![nitinprakash96](https://ziggit.dev/letter_avatar_proxy/v4/letter/n/f05b48/32.png) [@nitinprakash96](https://ziggit.dev/u/nitinprakash96)\
**Post date:** [July 31, 2023, 4:42am UTC](https://ziggit.dev/t/what-does-error-expected-type-t-found-const-t-mean-where-t-is-some-type/1320/3 "2023-07-31T04:42:58Z")

</div>

> [@zraineri](#):
>
> Variables are immutable unless defined otherwise.

Aha!! Makes sense. This was such an oversight from me. Thank you 🙂

---

<div class="post-metadata">

**Author:** ![zraineri](https://ziggit.dev/user_avatar/ziggit.dev/zraineri/32/755_2.png) [@zraineri](https://ziggit.dev/u/zraineri)\
**Post date:** [July 31, 2023, 4:46am UTC](https://ziggit.dev/t/what-does-error-expected-type-t-found-const-t-mean-where-t-is-some-type/1320/4 "2023-07-31T04:46:22Z")

</div>

No problem at all!

If you run into anything else feel free to ask away 🙂

---

<div class="post-metadata">

**Author:** ![squeek502](https://ziggit.dev/user_avatar/ziggit.dev/squeek502/32/409_2.png) [@squeek502](https://ziggit.dev/u/squeek502)\
**Post date:** [July 31, 2023, 7:09am UTC](https://ziggit.dev/t/what-does-error-expected-type-t-found-const-t-mean-where-t-is-some-type/1320/5 "2023-07-31T07:09:26Z")

</div>

Note that passing the allocator by pointer is not the way to do things anymore (since [Allocgate by leecannon · Pull Request #10055 · ziglang/zig · GitHub](https://github.com/ziglang/zig/pull/10055) which changed `allocator` into a function [instead of a field that you’d take the pointer of]). Your `init` function should therefore just take

```zig
allocator: std.mem.Allocator

```

and same for the `allocator` field of the `Converter` struct.

---

<div class="post-metadata">

**Author:** ![nitinprakash96](https://ziggit.dev/letter_avatar_proxy/v4/letter/n/f05b48/32.png) [@nitinprakash96](https://ziggit.dev/u/nitinprakash96)\
**Post date:** [July 31, 2023, 2:30pm UTC](https://ziggit.dev/t/what-does-error-expected-type-t-found-const-t-mean-where-t-is-some-type/1320/6 "2023-07-31T14:30:10Z")

</div>

Interesting. Thanks for letting me know. I’ll read up more on that and change my code accordingly 😃
