INSQUE(3POSIX)
π INSQUE(3POSIX) β the POSIX Programmer's Manual page, but make it make sense π
okay bestie, gather round, we're doing a <search.h> deep dive today and honestly? it's giving linked-list realness. this is the POSIX Programmer's Manual page for insque and remque, and the Linux version of this interface may lowkey differ (so pls consult the corresponding Linux manual page for the deets on Linux behavior), or the interface might not even be implemented on Linux at all. iykyk. π¦
β¨ PROLOG β¨
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.
not me telling you twice but fr fr, this is the POSIX spec, not the Linux spec. check both. π
π NAME π
insque, remque β insert or remove an element in a queue
like. the whole vibe. insert. remove. queue. periodt. π
πΈ SYNOPSIS πΈ
#include <search.h>
void insque(void *element, void *pred);
void remque(void *element);
two functions. that's it. no cap. π
π DESCRIPTION π
So. The insque() and remque() functions shall manipulate queues built from doubly-linked lists. The queue can be either circular or linear β your call, main character energy, choose your own adventure. π¦
An application using insque() or remque() 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. Translation:
- member one = a forward pointer to the next entry in the queue β‘οΈ
- member two = 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 β call them whatever, she's flexible like that. π
The insque() function shall insert the element pointed to by element into a queue immediately after the element pointed to by pred.
The remque() function shall remove the element pointed to by element from a queue.
If the queue is to be used as a linear list, invoking insque(&element, NULL), where element is the initial element of the queue, shall initialize the forward and backward pointers of element 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. yes, pointing at itself. she's self-referential AND thriving. π
π RETURN VALUE π
The insque() and remque() functions do not return a value.
void. silent. mysterious. iconic. π
π ERRORS π
No errors are defined.
The following sections are informative.
β EXAMPLES β
π§ 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);
NULL first because element1 is the beginning of the whole thing, then element2 slides in right after element1. slay. β¨
π§ 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);
see how element1 points at ITSELF first? that's the circular setup, bestie, she's her own best friend π«Ά
π§ Removing an Element
The following example removes the element pointed to by element1.
#include <search.h>
...
struct myque element1;
...
remque (&element1);
gone. bye. she left the group chat. π
π APPLICATION USAGE π
okay this part is the lore. π
The historical implementations of these functions described the arguments as being of type struct qelem * rather than as being of type void * as defined here. In those implementations, struct qelem was 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 used struct qelem as specified. messy. π
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 to struct qelem to avoid compilation warnings. By specifying void * as the argument type, applications do not need to change (unless they specifically referenced struct qelem and depended on it being defined in <search.h>).
so basically: void * said "no more casting drama," and honestly? she ate. π₯
π RATIONALE π
None.
the devs said "no thoughts, head empty." respect. π
π FUTURE DIRECTIONS π
None.
she's not going anywhere. stable queen. π
π¦ SEE ALSO π¦
The Base Definitions volume of POSIX.1β2017, <search.h>
πΈ COPYRIGHT πΈ
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 at http://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, see https://www.kernel.org/doc/man-pages/reporting_bugs.html .
and that's the whole page, bestie!! π this one came to you courtesy of IEEE/The Open Group, 2017 β the INSQUE(3POSIX) of it all β so if you cite it, cite her properly. now go build a doubly-linked list and be the main character of your own queue. πβ¨π
π¦ where this page comes from
- debian bookworm: manpages-posix-dev 2017a-2 Β· Other
- debian trixie: manpages-posix-dev 2017a-2 Β· Other
- ubuntu jammy: manpages-posix-dev 2017a-2 Β· Other
- ubuntu noble: manpages-posix-dev 2017a-2 Β· Other
- ubuntu resolute: manpages-posix-dev 2017a-2build1 Β· Other
- ubuntu stonking: manpages-posix-dev 2017a-2.1 Β· Other
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms