Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include "include/uv.h"
- #include "src/queue.h"
- #include <stdio.h>
- #include <stdlib.h>
- QUEUE wq;
- struct foobar {
- int a;
- QUEUE q;
- };
- typedef struct foobar foobar_t;
- foobar_t*
- foobar_new() {
- foobar_t* f = malloc(sizeof (foobar_t));
- f->a = -1;
- QUEUE_INIT(&(f->q));
- return f;
- }
- int main() {
- foobar_t* f;
- int i;
- QUEUE* head;
- QUEUE_INIT(&wq);
- for (i = 0; i < 10; i++) {
- f = foobar_new();
- f->a = i;
- QUEUE_INSERT_TAIL(&wq, &f->q);
- }
- while (!QUEUE_EMPTY(&wq)) {
- f = QUEUE_DATA(wq, foobar_t, q);
- printf("%d\n", f->a); /* This prints incorrect values */
- head = QUEUE_HEAD(&wq);
- QUEUE_REMOVE(head);
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement