I have a queue that is an array of chars, pointed to by a void pointer named data, this holds the correct address of 0x00008E80.
The tail of the queue is tracked by a simple index integer, in this case it is equal to 6, i.e. the 7th array position.
I'd like to return a pointer to the tail array position, which should be 0x00008E86.
I've tried the following (and some variations thereof) with no luck:
struct queue_t {
void * data;
uint16_t tail;
};
char sqData[SQ_LENGTH] = {0};
struct queue_t sq = {0};
void initQueue (queue_t * q, void * d) {
q->data = d;
}
char * getTailPositionAddress (context_t sc) {
char * s = (char *)sc->slave->queue->data;
return (s + sc->slave->queue->tail);
}
void main (void) {
initQueue(&sq, sqData);
foo_context->slave->queue = &sq;
// queue is of type struct queue_t *
// Do some stuff that pushes data to the queue and then pops a bit of it
// so the tail is moved up to the 7th array position
char * bar = getTailPositionAddress(fooContext);
// Here bar is always equal to some stupid low address like 0x5 or 0x2!?!
}
Why isn't this working? What would be the correct way to achieve what is intended? Thanks!
return sc->slave->queue->tail;?tailis an integer of some sort then your code is fine and 0x5 or 0x2 are the values pointed by the bar pointer.