httpd-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Nathanael Noblet <>
Subject Re: Apr array functions
Date Tue, 09 Nov 2004 02:02:07 GMT

On Nov 8, 2004, at 5:50 PM, Cliff Woolley wrote:

> Btw: didn't notice ahead of time that this discussion was on dev@httpd
> instead of dev@apr.  Oh well.

I didn't know there was one specifically for that, I had noticed a good 
deal of message dealing with APR so figured it would be as good as any 
place to ask.

> On Mon, 8 Nov 2004, Cliff Woolley wrote:
>> You don't have to remove elements to get at them... the array header
>> structure is visible to the application, so it can just do
>> arr->elts[index] and be done with it (insert bounds checking if
>> necessary).
> To be more precise, since arr->elts is a void pointer, you have to 
> insert
> a cast here.  But it doesn't have to be as complex looking as asking 
> the
> array structure how big each element is and explicitly multiplying.
> Presumably the application code knows what actualy type the data 
> stored in
> the array is, and thus a cast and pointer arithmetic will do the job 
> for
> you.
> ((foo_t *)arr->elts)[index]
> Or, even better:
> foo_t *f = arr->elts;
> f[index] ...

Even better solution I admit.
Though your assumption about the function I typed in my email, I did 
type it off the top of my head thus the typos, lots of logic in there 
is actually from the apr_array_pop() function. If you didn't like the 
arithmetic on those structure members, perhaps someone should look 
there. I'm not saying this because I'm hurt or angry, just to inform 
you of the fact that it exists in the apr source...

Thank you for the response and the better array indexing above..

Nathanael D. Noblet
Gnat Solutions
204 - 131 Gorge Road E
Victoria, BC V9A 1L1

T/F 250.385.4613

View raw message