📄 insque.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-2004 IEEE and 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, 2004 Edition<br>Copyright © 2001-2004 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 <<a href="../basedefs/search.h.html">search.h</a>><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 beeither circular or linear. An application using <i>insque</i>() or <i>remque</i>() shall ensure it defines a structure in which thefirst 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 tothe previous entry in the queue. If the queue is linear, the queue is terminated with null pointers. The names of the structure andof 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 elementpointed 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>(&<i>element</i>, NULL), where <i>element</i> is theinitial 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 backwardpointer 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 <search.h>...struct myque element1;struct myque element2;<br>char *data1 = "DATA1";char *data2 = "DATA2";...element1.data = data1;element2.data = data2;<br>insque (&element1, NULL);insque (&element2, &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 <search.h>...struct myque element1;struct myque element2;<br>char *data1 = "DATA1";char *data2 = "DATA2";...element1.data = data1;element2.data = data2;<br>element1.fwd = &element1;element1.bck = &element1;<br>insque (&element2, &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 <search.h>...struct myque element1;...remque (&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 asbeing 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><search.h></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 theactual data contained in the elements. Most applications defined structures that contained the two pointers as the initial elementsand also provided space for, or pointers to, the object's data. Applications that used these functions to update more than one typeof table also had the problem of specifying two or more different structures with the same name, if they literally used <b>structqelem</b> as specified.</p><p>As described here, the implementations were actually expecting a structure type where the first two members were forward andbackward pointers to structures. With C compilers that didn't provide function prototypes, applications used structures asspecified in the DESCRIPTION above and the compiler did what the application expected.</p><p>If this method had been carried forward with an ISO C standard compiler and the historical function prototype, mostapplications would have to be modified to cast pointers to the structures actually used to be pointers to <b>struct qelem</b> toavoid compilation warnings. By specifying <b>void *</b> as the argument type, applications do not need to change (unless theyspecifically referenced <b>struct qelem</b> and depended on it being defined in <a href="../basedefs/search.h.html"><i><search.h></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 Std 1003.1-2001, <a href="../basedefs/search.h.html"><i><search.h></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 "must" for application requirements.</p></blockquote><div class="box"><em>End of informative text.</em></div><hr size="2" noshade><center><font size="2"><!--footer start-->UNIX ® is a registered Trademark of The Open Group.<br>POSIX ® 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>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -