Re: array inside a array!?
From: Flash Gordon (spam_at_flash-gordon.me.uk)
Date: 12/14/04
- Next message: dandelion: "Re: about sprintf function"
- Previous message: Richard Bos: "Re: 0 insted of '\0' in char ptr"
- In reply to: sathya: "Re: array inside a array!?"
- Next in thread: Lawrence Kirby: "Re: array inside a array!?"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Date: Tue, 14 Dec 2004 12:57:45 +0000
On Tue, 14 Dec 2004 17:25:56 +0530
sathya <sathya@nomail.com> wrote:
> sathya wrote:
>
> > I was going through an Boyer-Moore-Horspool pattern match, I saw
> > a
> > array inside a array, like the below,
> >
> > skip[pat[i] ] = patlen - i - 1;
> >
> > The array is decleared as
> >
> > int skip[UCHAR_MAX+1];
> >
> > unsigned char *pat;
> >
> > I have seen function call inside the array such as calling strlen()
> > inside a array, but the above one is
> > strange and new to me as a beginner. Can anybody spend a little time
> > to explain the above.
> > BTW, if this a FAQ please refer the question number.
> >
>
> Sorry I must be more precise in my question. The bellow properties
> is well known with the array:
>
> "In an array, LOGICAL ADJACENCY (B follows A) is modeled by
> PHYSICAL ADJACENCY (B occurs just after A in memory.)"
>
> As in the case of the above "array inside a array" I cannot figure
> out the possibility of logical and
> physical adjacency. And is the above kind of "array inside a array"
> is UD in std?
It's simple. You do *not* have an array inside an array, you are just
looking in one array to find an index in to the other. It is basically
equivalent to:
int skip[UCHAR_MAX+1];
unsigned char *pat;
unsigned char tmp;
tmp = pat[i];
skip[ tmp ] = patlen - i - 1;
<pedantic>
C does not guarantee physical adjacency, only logical adjacency. For
example, on a system with paged memory one location in the array might
be in physical memory whilst the next location, on the other side of a
page boundary, might have been swapped out to disk and not exist in
physical memory at all.
</pedantic>
If you want to look at formal definitions with respect to C you really
need to look at the C standard in my opinion. Google for N869 to find
the publicly available last draft of the C99 standard.
-- Flash Gordon Living in interesting times. Although my email address says spam, it is real and I read it.
- Next message: dandelion: "Re: about sprintf function"
- Previous message: Richard Bos: "Re: 0 insted of '\0' in char ptr"
- In reply to: sathya: "Re: array inside a array!?"
- Next in thread: Lawrence Kirby: "Re: array inside a array!?"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Relevant Pages
|