[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index][Thread Index][Top&Search][Original]
Re: C coding questions for [perl #58182] Unicode problem
On Sun, Oct 19, 2008 at 08:59:57PM -0600, karl williamson wrote:
> I only wanted to know if I have to be think about exceeding array
> bounds. If it's exactly 8 bits and unsigned, there's no way for it to
> reference outside a 256 element array.
I think that the perl source code is already making that assumption in places.
But I doubt that there's a size or speed penalty in masking it with 0xFF,
as any sane optimiser would spot that it's a no-op and eliminate the code.
I tried:
$ cat index.c
#include <stdlib.h>
#include <stdio.h>
#ifndef MASK
# define MASK
#endif
static unsigned char buffer[256];
int main (int argc, char **argv) {
unsigned int count = sizeof(buffer);
while (count--)
buffer[count MASK] = ~count;
while (*++argv) {
const unsigned char i = (unsigned char) atoi(*argv);
printf("%s: %d\n", *argv, buffer[i MASK]);
}
return 0;
}
$ gcc -Wall -c -O index.c
$ ls -l index.o
-rw-r--r-- 1 nick nick 1752 Oct 20 19:26 index.o
$ gcc -Wall -o index -O -DMASK='& 255' index.c
$ ls -l index.o
-rw-r--r-- 1 nick nick 1752 Oct 20 19:26 index.o
Nicholas Clark
- Follow-Ups from:
-
Marcus Holland-Moritz <mhx-perl@gmx.net>
- References to:
-
karl williamson <public@khwilliamson.com>
Glenn Linderman <perl@NevCal.com>
karl williamson <public@khwilliamson.com>
"Rafael Garcia-Suarez" <rgarciasuarez@gmail.com>
karl williamson <public@khwilliamson.com>
"Rafael Garcia-Suarez" <rgarciasuarez@gmail.com>
Nicholas Clark <nick@ccl4.org>
karl williamson <public@khwilliamson.com>
[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index][Thread Index][Top&Search][Original]