Date: Fri, 16 Nov 2007 07:10:20 +0100 From: deeptech71@gmail.com To: freebsd-chat@freebsd.org Subject: C out-of-bound pointer question Message-ID: <473D344C.1080805@gmail.com>
next in thread | raw e-mail | index | archive | help
int x[N]; Values in x[] are (rand()%10)+268435410, aka 268435410..268435419. The algorith counts each individual value. // v1.0 uses if( x[n] == ___ )'s // v2.0: int k[268435420] = {0}; // k uses almost 1GB of memory for (n = 0; n < N; n++) { k[ x[n] ]++; } // v2.1: int k[10] = {0}; int* p = k-268435410; for (n = 0; n < N; n++) { p[ x[n] ]++; } The values in x[] are guaranteed, so k[ x[n]-268435410 ] are k[0] to k[9], but is *((k-268435410)+26843541_) safe? (as long as I do no dereference such out-of-bound memory region)
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?473D344C.1080805>