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:

  1. 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] 
  2. 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 } 
  3. 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?

displaced := array[offset:] 

just slice it.

demo.


Comments

Popular posts from this blog

php - Vagrant up error - Uncaught Reflection Exception: Class DOMDocument does not exist -

vue.js - Create hooks for automated testing -

.htaccess - ERR_TOO_MANY_REDIRECTS htaccess -