#What is the difference of a many-item pointer [*]T and an Array [N]T?

1 messages · Page 1 of 1 (latest)

potent cloak
#

it's kind of what c has

#

its a pointer to an unknown amount of items

#

it's also what you get when you do []T.ptr

#

a slice "[]T" is just a [*] and a length

#

an array on the other hand, is not pointers. it's a real list of T

agile slate
#

I feel like some information about arrays are missing on the docs

#

I mean, that seems pretty important

potent cloak
#

like what?

agile slate
#

I read the whole array section thinking of pointers

potent cloak
#

this is the standard definition of an Array in basically all languages

#

nothing new

agile slate
#

yeah

agile slate
#

which are basically pointers

#

sorry

potent cloak
#

C arrays are not pointers actually

#

but i get what you mean

agile slate
#

all my life I thought of them as pointers

potent cloak
#

nope, they just freely coerce to the pointer of the element

#

in C terms, [*] is basically char* hello = "hello" and [N]T is like char hello[10]

agile slate
#

ah, just to be clear

#

I know that in C:

char* hello = "hello";

// is not the same as 

int x[10];
#

but the hello right there is in fact a pointer isn't it?

potent cloak
#

the variable hello in your example is a pointer to the first element of the array

agile slate
#

exactly

#

all my life I thought that all arrays

#

even the x in my example were in fact pointers to the first element

#

that's something pretty dumb, but I never actually thought about what an array is lol

#

I just assumed they were pointers

potent cloak
#

just a region of memory thats next to each other

agile slate
#

yeah

#

anyway, thanks for clarifying

potent cloak
#

yes