pervognsen / bitwise

Bitwise is an educational project where we create the software/hardware stack for a computer from scratch.
Other
5.14k stars 212 forks source link

Ion cast to void** #64

Open tjpalmer opened 6 years ago

tjpalmer commented 6 years ago

In ion, any pointer type seems to auto cast to void*, but they don't auto-cast to void**. For example, I have to cast from char** to void** here:

str: char* = NULL;
buf_push((:void**)&str, &val, 1);

Where I elsewhere have the following function:

func buf_push(b: void**, elem: void*, elem_size: usize) {
    buf_fit(b, 1 + buf_len(*b), elem_size);
    memcpy((:char*)*b + elem_size * buf__hdr(*b).len++, elem, elem_size);
}

If I leave out the cast, it says the following:

error: Invalid type in function call argument. Expected void**, got char**

I understand that there are bizarre edge cases for pointers on various ancient or strange systems. So maybe this is by design because of edge cases that I haven't studied well. But in my mind, this ought to work. If it should work, then it would be nice to automate it.

If it shouldn't work, then I clearly need to design the example function differently ...