c3c icon indicating copy to clipboard operation
c3c copied to clipboard

Implicit cast from array to vector pointer changes alignment requirement

Open cbuttner opened this issue 1 year ago • 5 comments

Not a bug, but:

fn void test(float[<4>]* out) {
  *out *= 2;
}

fn int main(String[] args) {
  float[4] v;
  test(&v); // This implicitly changes the alignment requirement of v
}

cbuttner avatar Jul 14 '24 16:07 cbuttner

Yes. I'm not sure whether this is wrong though.

lerno avatar Jul 14 '24 16:07 lerno

This can go completely unnoticed, in fact it almost did for me, especially when the alignment just happens to match up. Then one day it just crashes and you're left wondering why. I'm generally not that worried about footguns, but man, you've got to tighten up some of these implicit conversions. I don't even understand what the benefit of this is, saving a few characters needed to type for an explicit cast?

cbuttner avatar Jul 14 '24 20:07 cbuttner

Indeed. Since the opposite is fine too.

lerno avatar Jul 14 '24 21:07 lerno

Master is updated.

lerno avatar Jul 14 '24 21:07 lerno

Please check that it's working correctly for this and other similar pointer conversions.

lerno avatar Jul 15 '24 01:07 lerno

Is this working?

lerno avatar Aug 02 '24 16:08 lerno

Yes this works well, thank you.

cbuttner avatar Aug 03 '24 20:08 cbuttner