Files
oldlinux-files/Ref-docs/POSIX/susv3/functions/insque.html
2024-02-19 00:21:47 -05:00

221 lines
7.7 KiB
HTML

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<meta name="generator" content="HTML Tidy, see www.w3.org">
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<link type="text/css" rel="stylesheet" href="style.css"><!-- Generated by The Open Group's rhtm tool v1.2.1 -->
<!-- Copyright (c) 2001 The Open Group, All Rights Reserved -->
<title>insque</title>
</head>
<body bgcolor="white">
<script type="text/javascript" language="JavaScript" src="../jscript/codes.js">
</script>
<basefont size="3"> <a name="insque"></a> <a name="tag_03_281"></a><!-- insque -->
<!--header start-->
<center><font size="2">The Open Group Base Specifications Issue 6<br>
IEEE Std 1003.1-2001<br>
Copyright &copy; 2001 The IEEE and The Open Group, All Rights reserved.</font></center>
<!--header end-->
<hr size="2" noshade>
<h4><a name="tag_03_281_01"></a>NAME</h4>
<blockquote>insque, remque - insert or remove an element in a queue</blockquote>
<h4><a name="tag_03_281_02"></a>SYNOPSIS</h4>
<blockquote class="synopsis">
<div class="box"><code><tt><sup>[<a href="javascript:open_code('XSI')">XSI</a>]</sup> <img src="../images/opt-start.gif" alt=
"[Option Start]" border="0"> #include &lt;<a href="../basedefs/search.h.html">search.h</a>&gt;<br>
<br>
void insque(void *</tt><i>element</i><tt>, void *</tt><i>pred</i><tt>);<br>
void remque(void *</tt><i>element</i><tt>); <img src="../images/opt-end.gif" alt="[Option End]" border="0"></tt></code></div>
<tt><br>
</tt></blockquote>
<h4><a name="tag_03_281_03"></a>DESCRIPTION</h4>
<blockquote>
<p>The <i>insque</i>() and <i>remque</i>() functions shall manipulate queues built from doubly-linked lists. The queue can be
either circular or linear. An application using <i>insque</i>() or <i>remque</i>() 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.</p>
<p>The <i>insque</i>() function shall insert the element pointed to by <i>element</i> into a queue immediately after the element
pointed to by <i>pred</i>.</p>
<p>The <i>remque</i>() function shall remove the element pointed to by <i>element</i> from a queue.</p>
<p>If the queue is to be used as a linear list, invoking <i>insque</i>(&amp;<i>element</i>, NULL), where <i>element</i> is the
initial element of the queue, shall initialize the forward and backward pointers of <i>element</i> to null pointers.</p>
<p>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.</p>
</blockquote>
<h4><a name="tag_03_281_04"></a>RETURN VALUE</h4>
<blockquote>
<p>The <i>insque</i>() and <i>remque</i>() functions do not return a value.</p>
</blockquote>
<h4><a name="tag_03_281_05"></a>ERRORS</h4>
<blockquote>
<p>No errors are defined.</p>
</blockquote>
<hr>
<div class="box"><em>The following sections are informative.</em></div>
<h4><a name="tag_03_281_06"></a>EXAMPLES</h4>
<blockquote>
<h5><a name="tag_03_281_06_01"></a>Creating a Linear Linked List</h5>
<p>The following example creates a linear linked list.</p>
<pre>
<tt>#include &lt;search.h&gt;
...
struct myque element1;
struct myque element2;
<br>
char *data1 = "DATA1";
char *data2 = "DATA2";
...
element1.data = data1;
element2.data = data2;
<br>
insque (&amp;element1, NULL);
insque (&amp;element2, &amp;element1);
</tt>
</pre>
<h5><a name="tag_03_281_06_02"></a>Creating a Circular Linked List</h5>
<p>The following example creates a circular linked list.</p>
<pre>
<tt>#include &lt;search.h&gt;
...
struct myque element1;
struct myque element2;
<br>
char *data1 = "DATA1";
char *data2 = "DATA2";
...
element1.data = data1;
element2.data = data2;
<br>
element1.fwd = &amp;element1;
element1.bck = &amp;element1;
<br>
insque (&amp;element2, &amp;element1);
</tt>
</pre>
<h5><a name="tag_03_281_06_03"></a>Removing an Element</h5>
<p>The following example removes the element pointed to by <i>element1</i>.</p>
<pre>
<tt>#include &lt;search.h&gt;
...
struct myque element1;
...
remque (&amp;element1);
</tt>
</pre>
</blockquote>
<h4><a name="tag_03_281_07"></a>APPLICATION USAGE</h4>
<blockquote>
<p>The historical implementations of these functions described the arguments as being of type <b>struct qelem *</b> rather than as
being of type <b>void *</b> as defined here. In those implementations, <b>struct qelem</b> was commonly defined in <a href=
"../basedefs/search.h.html"><i>&lt;search.h&gt;</i></a> as:</p>
<pre>
<tt>struct qelem {
struct qelem *q_forw;
struct qelem *q_back;
};
</tt>
</pre>
<p>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 <b>struct
qelem</b> as specified.</p>
<p>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.</p>
<p>If this method had been carried forward with an ISO&nbsp;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 <b>struct qelem</b> to
avoid compilation warnings. By specifying <b>void *</b> as the argument type, applications do not need to change (unless they
specifically referenced <b>struct qelem</b> and depended on it being defined in <a href=
"../basedefs/search.h.html"><i>&lt;search.h&gt;</i></a>).</p>
</blockquote>
<h4><a name="tag_03_281_08"></a>RATIONALE</h4>
<blockquote>
<p>None.</p>
</blockquote>
<h4><a name="tag_03_281_09"></a>FUTURE DIRECTIONS</h4>
<blockquote>
<p>None.</p>
</blockquote>
<h4><a name="tag_03_281_10"></a>SEE ALSO</h4>
<blockquote>
<p>The Base Definitions volume of IEEE&nbsp;Std&nbsp;1003.1-2001, <a href=
"../basedefs/search.h.html"><i>&lt;search.h&gt;</i></a></p>
</blockquote>
<h4><a name="tag_03_281_11"></a>CHANGE HISTORY</h4>
<blockquote>
<p>First released in Issue 4, Version 2.</p>
</blockquote>
<h4><a name="tag_03_281_12"></a>Issue 5</h4>
<blockquote>
<p>Moved from X/OPEN UNIX extension to BASE.</p>
</blockquote>
<h4><a name="tag_03_281_13"></a>Issue 6</h4>
<blockquote>
<p>The DESCRIPTION is updated to avoid use of the term &quot;must&quot; for application requirements.</p>
</blockquote>
<div class="box"><em>End of informative text.</em></div>
<hr>
<hr size="2" noshade>
<center><font size="2"><!--footer start-->
UNIX &reg; is a registered Trademark of The Open Group.<br>
POSIX &reg; is a registered Trademark of The IEEE.<br>
[ <a href="../mindex.html">Main Index</a> | <a href="../basedefs/contents.html">XBD</a> | <a href=
"../utilities/contents.html">XCU</a> | <a href="../functions/contents.html">XSH</a> | <a href="../xrat/contents.html">XRAT</a>
]</font></center>
<!--footer end-->
<hr size="2" noshade>
</body>
</html>