Can I use a "displaced" array base in Go? -
i have problem solved using "displaced array base". is, in c set pointer array-base + offset, , access array using ptr[x]
array[offset + x]
without addition.
is such thing possible in go? i've read, can't find support (including statement there no pointer arithmetic in go), slices , other things i'm unfamiliar far, i'd more experienced opinion.
edit
consider 3 possible scenarios:
i create array, , want use "middle index" of array base:
sign_values := { -1, -1, -1, -1, -1, 0, 1, 1, 1, 1, 1 } sign := sign + 5 = f(x) // returns [-5 .. 5] sign_i = sign[i]
i create array, , want use "negative offset" of array base:
to_lower := { 'a', 'b', 'c', 'd', 'e', ..., 'z' } tolower := to_lower - 'a' func tolower(ch byte) byte { if isupper(ch) { return tolower[ch] } return ch }
i create array , want use "excessive positive" index base. same others, except expectation indices negative. no idea when useful.
in of cases, there requirement either negative index (case 1, case 3), or negative offset (case 2). far can tell, disallowed @ least prohibition on negative indices.
but maybe not?
Comments
Post a Comment