Movatterモバイル変換


[0]ホーム

URL:


man7.org > Linux >man-pages

Linux/UNIX system programming training


insque(3p) — Linux manual page

PROLOG |NAME |SYNOPSIS |DESCRIPTION |RETURN VALUE |ERRORS |EXAMPLES |APPLICATION USAGE |RATIONALE |FUTURE DIRECTIONS |SEE ALSO |COPYRIGHT

INSQUE(3P)              POSIX Programmer's ManualINSQUE(3P)

PROLOG        top

       This manual page is part of the POSIX Programmer's Manual.  The       Linux implementation of this interface may differ (consult the       corresponding Linux manual page for details of Linux behavior), or       the interface may not be implemented on Linux.

NAME        top

       insque, remque — insert or remove an element in a queue

SYNOPSIS        top

       #include <search.h>       void insque(void *element, void *pred);       void remque(void *element);

DESCRIPTION        top

       Theinsque() andremque() functions shall manipulate queues built       from doubly-linked lists.  The queue can be either circular or       linear. An application usinginsque() orremque() shall ensure it       defines a structure in which the first two members of the       structure are pointers to the same type of structure, and any       further members are application-specific. The first member of the       structure is a forward pointer to the next entry in the queue. The       second member is a backward pointer to the previous entry in the       queue.  If the queue is linear, the queue is terminated with null       pointers. The names of the structure and of the pointer members       are not subject to any special restriction.       Theinsque() function shall insert the element pointed to byelement into a queue immediately after the element pointed to bypred.       Theremque() function shall remove the element pointed to byelement from a queue.       If the queue is to be used as a linear list, invokinginsque(&element, NULL), whereelement is the initial element of       the queue, shall initialize the forward and backward pointers ofelement to null pointers.       If the queue is to be used as a circular list, the application       shall ensure it initializes the forward pointer and the backward       pointer of the initial element of the queue to the element's own       address.

RETURN VALUE        top

       Theinsque() andremque() functions do not return a value.

ERRORS        top

       No errors are defined.The following sections are informative.

EXAMPLES        top

Creating a Linear Linked List       The following example creates a linear linked list.           #include <search.h>           ...           struct myque element1;           struct myque element2;           char *data1 = "DATA1";           char *data2 = "DATA2";           ...           element1.data = data1;           element2.data = data2;           insque (&element1, NULL);           insque (&element2, &element1);Creating a Circular Linked List       The following example creates a circular linked list.           #include <search.h>           ...           struct myque element1;           struct myque element2;           char *data1 = "DATA1";           char *data2 = "DATA2";           ...           element1.data = data1;           element2.data = data2;           element1.fwd = &element1;           element1.bck = &element1;           insque (&element2, &element1);Removing an Element       The following example removes the element pointed to byelement1.           #include <search.h>           ...           struct myque element1;           ...           remque (&element1);

APPLICATION USAGE        top

       The historical implementations of these functions described the       arguments as being of typestruct qelem *rather than as being of       typevoid *as defined here. In those implementations,structqelemwas commonly defined in<search.h> as:           struct qelem {               struct qelem  *q_forw;               struct qelem  *q_back;           };       Applications using these functions, however, were never able to       use this structure directly since it provided no room for the       actual data contained in the elements. Most applications defined       structures that contained the two pointers as the initial elements       and also provided space for, or pointers to, the object's data.       Applications that used these functions to update more than one       type of table also had the problem of specifying two or more       different structures with the same name, if they literally usedstruct qelemas specified.       As described here, the implementations were actually expecting a       structure type where the first two members were forward and       backward pointers to structures. With C compilers that didn't       provide function prototypes, applications used structures as       specified in the DESCRIPTION above and the compiler did what the       application expected.       If this method had been carried forward with an ISO C standard       compiler and the historical function prototype, most applications       would have to be modified to cast pointers to the structures       actually used to be pointers tostruct qelemto avoid compilation       warnings. By specifyingvoid *as the argument type, applications       do not need to change (unless they specifically referencedstructqelemand depended on it being defined in<search.h>).

RATIONALE        top

       None.

FUTURE DIRECTIONS        top

       None.

SEE ALSO        top

       The Base Definitions volume of POSIX.1‐2017,search.h(0p)

COPYRIGHT        top

       Portions of this text are reprinted and reproduced in electronic       form from IEEE Std 1003.1-2017, Standard for Information       Technology -- Portable Operating System Interface (POSIX), The       Open Group Base Specifications Issue 7, 2018 Edition, Copyright       (C) 2018 by the Institute of Electrical and Electronics Engineers,       Inc and The Open Group.  In the event of any discrepancy between       this version and the original IEEE and The Open Group Standard,       the original IEEE and The Open Group Standard is the referee       document. The original Standard can be obtained online athttp://www.opengroup.org/unix/online.html .       Any typographical or formatting errors that appear in this page       are most likely to have been introduced during the conversion of       the source files to man page format. To report such errors, seehttps://www.kernel.org/doc/man-pages/reporting_bugs.html .IEEE/The Open Group                2017INSQUE(3P)

Pages that refer to this page:search.h(0p)remque(3p)



HTML rendering created 2025-09-06 byMichael Kerrisk, author ofThe Linux Programming Interface.

For details of in-depthLinux/UNIX system programming training courses that I teach, lookhere.

Hosting byjambit GmbH.

Cover of TLPI


[8]ページ先頭

©2009-2025 Movatter.jp