#single item pointer to many item pointer

1 messages · Page 1 of 1 (latest)

dim jungle
#

hi, i was doing ziglings 61 and i saw that "single-item mutable pointers coerce to single-item pointers pointing to an array of length 1" (why only mutable?) and that "single-item pointers to arrays coerce to slices and many item pointers"

why is it that attempting to cast a single item pointer to a many item pointer is an error? shouldn't the single item pointer coerce to an array pointer which can coerce to a many item pointer?

shell pecan
#

a wacky side effect of many-item pointers is that they can also point to 0 items

#

which, by extent, would mean that accessing the first item of a many-pointer with 0 items would be illegal behavior

#

you can't really tell how many items there are behind a many-item pointer without keeping track of the amount, or by keeping track of the sentinel, or (in some rare cases) with special logic in your program

#

why is why, i assume, that you can't easily cast a single-item pointer to a many-item pointer, important information would be lost

#

though you can always @ptrCast, i'm pretty sure

dim jungle
shell pecan
#

yeah, i assume it's a pattern common enough to warrant that

#

maybe the mental gymnastics between single-item to many-item is too big

coral quiver
#

the *T -> *[1]T is going away fwiw

shell pecan
#

right, i wanted to say that but i didn't want to accidentally spread misinfo

shell pecan
coral quiver
shell pecan
#

oh, i specifically remember mlugg's comment

#

right, yeah

dim jungle