c - sys/queue.h error: request for member in something not a structure or union (TAILQ) -


i'm building small file utility relies on queues , i've been getting error on compile:

error: request member "entries" in not structure or union 

i stripped down queue handling lines, , i'm getting same error, here's source header:

#ifndef _tailq_test_h #define _tailq_test_h  #include <stdlib.h> #include <stdint.h> #include <unistd.h> #include <sys/queue.h>  struct tail_q {     tailq_entry(tail_q) entries;     int item; };  tailq_head(tail_queue, tail_q);  static struct tail_queue queue;  int main();  #endif 

and program:

#include <stdlib.h> #include <stdint.h> #include <unistd.h> #include <sys/queue.h> #include "tailq-test.h"  static struct tail_queue queue;  int main() {     struct tail_q *q_ptr;     int data = 1;      tailq_init(&queue);      tailq_insert_head(&queue, &data, entries);      return 0; } 

the traceback refers line tailq_insert_head(&queue, &data, entries);, has same effect if tailq_insert_tail used instead.

i'm not sure why it's not compiling. checked answer this question , provided example compiled fine. i'm having trouble spotting difference/what i'm doing wrong.

any appreciated.

i wasn't familiar tailq, took @ source code can find here : http://www.gnu.org/software/mifluz/doc/doxydoc/queue_8h-source.html

here source code tailq_insert_head :

#define tailq_insert_head(head, elm, field) {                                  if (((elm)->field.tqe_next = (head)->tqh_first) != null)                          (head)->tqh_first->field.tqe_prev =                                           &(elm)->field.tqe_next; 

as can see, second parameter elm needs struct containing third parameter member (field).

in situation, second parameter int *, not have entries member pointed out error message.

from understanding, must pass tail_q struct second parameter code compile.

edit : example, following code compiles :

int main() {     struct tail_q q;     int data = 1;     q.item = data; // include data in struct.      tailq_init(&queue);      tailq_insert_head(&queue, &q, entries); // notice passing tail_q pointer here.      return 0; } 

Comments