INSQUE(3P)
π INSQUE(3P) π
okay bestie, welcome to the POSIX Programmer's Manual page for insque and remque β yes that's the manual name right there, INSQUE(3P), we're in the POSIX programmer's manual section, periodt. π
β¨ PROLOG β¨
so like, real talk first: this manual page is part of the POSIX Programmer's Manual. The Linux implementation of this interface may differ β so if you're on Linux, consult the corresponding Linux manual page for details of Linux behavior β or honestly the interface may not even be implemented on Linux at all. π
πΈ NAME πΈ
insque, remque β insert or remove an element in a queue
π¦ SYNOPSIS π¦
#include <search.h>
void insque(void *element, void *pred);
void remque(void *element);
π DESCRIPTION π
okay so here's the tea. The insque() and remque() functions shall manipulate queues built from doubly-linked lists. The queue can be either circular or linear, your choice, main character energy either way. β¨
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. So:
- 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 β name them whatever, no one's judging, we love freedom. π«Ά
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. it's giving self-referential, it's giving ouroboros, we love her π
β RETURN VALUE β
The insque() and remque() functions do not return a value. nothing. void. silent. mysterious. π
π 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);
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 by element1.
#include <search.h>
...
struct myque element1;
...
remque (&element1);
π APPLICATION USAGE π
okay so this is the history lesson part and honestly it's juicy. π
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. like bestie where is the data. π 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. imagine the chaos, the drama, the name collisions π
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. slay, no notes, it just worked.
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 iconic of them honestly, they fixed it, they ate. π
π₯ RATIONALE π₯
None.
π§ FUTURE DIRECTIONS π§
None.
π 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, brought to you by IEEE/The Open Group, 2017, INSQUE(3P) β that's the source, the version and the date all in one, consider yourself signed off, mwah π β¨
π¦ where this page comes from
- alpine 3.22: man-pages-posix 2017a-r0 Β· custom
- alpine 3.23: man-pages-posix 2017a-r0 Β· custom
- alpine 3.24: man-pages-posix 2017a-r0 Β· custom
- arch rolling: man-pages 6.19-1
- arch rolling: man-pages 6.20-1 Β· BSD-2-Clause AND BSD-3-Clause AND BSD-4.3TAHOE AND BSD-4-Clause-UC AND GPL-1.0-or-later AND GPL-2.0-only AND GPL-2.0-or-later AND GPL-3.0-or-later AND LGPL-3.0-linking-exception AND LGPL-3.0-or-later AND LicenseRef-Public-Domain AND LicenseRef-UltraPermissive AND Linux-man-pages-1-para AND Linux-man-pages-copyleft AND Linux-man-pages-copyleft-2-para AND Linux-man-pages-copyleft-var AND MIT AND Spencer-94
- nixpkgs unstable: man-pages-posix 2017a
- opensuse-leap 16.0: man-pages-posix 2017a-160000.4.1 Β· SUSE-IEEE
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms