You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@apr.apache.org by Damir Dezeljin <pr...@nib.si> on 2002/11/08 11:30:49 UTC
apr_queue.c: a question (I don't realy understand this)
Hi.
I looked in the 'testqueue.c' sample from apr-util package (I checked out
it yesterday from the CVS). There is defined a function
consumer(apr_thread_t *thd, void *data)
which is used to get elements from the queue. *data is then casted to:
apr_queue_t *q = (apr_queue_t*)data;
Then on line 114 it is called
val = **(int**)v;
val is of type int (int val;). Then on the next line it is printed with
printf();
I realy don't understand this why I need to do **(int**) (four star hotel
;) ).
So I looked in the sources where apr_queue is implemented and I found:
struct apr_queue_t {
void **data;
...
}
Then in:
apr_queue_create(apr_queue_t **q, int queue_capacity, apr_pool_t *a)
an array of pointers to void * is alocated (apr_queue.c:169). So ...
queue->data[] is an array of pointers to void *
In function:
apr_queue_push(apr_queue_t *queue, void *data)
data is added to the queue on line 231:
queue->data[queue->in] = data;
Function:
apr_queue_pop(apr_queue_t *queue, void **data)
get data from the queue on the line 345:
*data = &queue->data[queue->out];
This is why **(int **) is needed in the test program. But why
queue->data[] is dereferenced (so why there is &)???
And what happend with the test program on a 64bit machine (I don't have
such a machine to test, but I think that pointers on such machines are 64
bit so that the cast **(int **) will do something wrong - I'm not shure on
this).
Regards,
Dezo